Today I'm facing a strange behavior which I couldn't figure out why.
Imagine we have a final variable in a typical class in Java. We can initialize it instantly or in class constructor like this:
public class MyClass {
private final int foo;
public MyClass() {
foo = 0;
}
}
But I don't know why we can't call a method in constructor and initialize foo
in that method, like this:
public class MyClass {
private final int foo;
public MyClass() {
bar();
}
void bar(){
foo = 0;
}
}
Because I think we are still in constructor flow and it doesn't finished yet. Any hint will be warmly appreciated.