I want to use Constructor Overloading in my class and I also would like to have some final variables to define.
The structure I would like to have is this:
public class MyClass{
private final int variable;
public MyClass(){
/* some code and
other final variable declaration */
variable = 0;
}
public MyClass(int value){
this();
variable = value;
}
}
I would like to call this() to avoid to rewrite the code in my first constructor but I have already defined the final variable so this give a compilation error. The most convenient solution I have in mind is to avoid the final keyword but of course it is the worst solution.
What can be the best way to define the variable in multiple constructors and avoid code repetitions?