I have an initializer method inside the parameterized constructor of a class. Right now this is how the class looks like
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
}
}
I recently learned about Lombok's @AllArgsConstructor
annotation which generates a parameterized constructor for a class. I want to use that here. However, I can't find a way to run the initializeSomeOtherStuff()
method inside the constructor generated by @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 OtherClass2(), new OtherClass3());
}
private void initializeSomeOtherStuff(){ // How to run this function in the constructor generated by @AllArgsConstructor
// some initializer code
}
}
Is this even possible? If it is please tell me how.