有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在Intellij Idea中提取私有静态常量?

要提取常量,我可以使用ctrl+alt+c,该“提取”创建公共常量:

public static final String CONST = "123";

所以我需要手动输入private。默认情况下,是否有方法提取具有私有作用域的常量


共 (2) 个答案

  1. # 1 楼答案

    按ctrl键两次(显示Extract Constant对话框)

    点击alt+v(将默认值Visibility设置为Private

    点击输入

    完成:)私有范围设置为默认值-因此您可以像以前一样使用常量提取,要更改默认范围,只需重复上述步骤,选择不同的范围

  2. # 2 楼答案

    试试这个:

    If the Enable in place refactorings check box is cleared on the Editor settings, the Extract Constant refactoring is performed by means of the Extract Constant Dialog dialog box.

    http://www.jetbrains.com/idea/webhelp/extract-constant.html

    “提取常量”对话框允许选择适当的常量范围

    设置->;编辑->;启用位置重构