问题描述
我在类的参数化构造函数中有一个初始化方法。现在这就是类的样子
public class Example{
private OtherClass1 otherClass1;
private OtherClass2 otherClass2;
private OtherClass3 otherClass3;
public Example(){
this(new OtherClass1(),new OtherClass2(),new OtherClass3());
}
public Example(OtherClass1 otherClass1,OtherClass2 otherClass2,OtherClass3 otherClass3){
this.otherClass1 = otherClass1;
this.otherClass2 = otherClass2;
this.otherClass3 = otherClass3;
initializeSomeOtherStuff();
}
private void initializeSomeOtherStuff(){
// some initializer code
}
}
我最近了解了 Lombok 的 @AllArgsConstructor
注释,它为类生成参数化构造函数。我想在这里使用它。但是,我找不到在 initializeSomeOtherStuff()
生成的构造函数中运行 @AllArgsConstructor
方法的方法。
@AllArgsConstructor // Generates the parameterized constructor for Example
public class Example{
private OtherClass1 otherClass1;
private OtherClass2 otherClass2;
private OtherClass3 otherClass3;
public Example(){
this(new OtherClass1(),new OtherClass3());
}
private void initializeSomeOtherStuff(){ // How to run this function in the constructor generated by @AllArgsConstructor
// some initializer code
}
}
这甚至可能吗?如果是,请告诉我如何。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)