我有简单的类(class):
public class A {
private int a;
private int b;
public A(int a) {
this.a = a;
}
}
现在我想添加 int b
到构造函数参数并用新参数初始化类字段。所以它最终必须是:
public A(int a, int b) {
this.a = a;
this.b = b;
}
那么,如果 IDEA
(AndroidStudio
) 有快捷方式呢?
P.S. Eclipse
同样的问题:Shortcut for adding fields to existing constructor
最佳答案
- 确保要添加到构造函数的字段是
private
- 用鼠标选择它的名字
- 按
Alt+Enter
- 选择
添加构造函数参数
关于java - 在 Android Studio 或 IDEA 中将类字段添加到现有构造函数的快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34692945/