Well, as far as I know, I understand these things about the final variable.
- It should only be appointed once.
- All
final variables must be initialized before the constructor completes.
Now, using the above, I don't understand how the below works:
public class FinalTest implements AnotherClass { private final Something something; private final otherthing; @Override public void setStuff(Something something) { this.something = something; this.otherthing = new SomeClass(something); } public FinalTest(Something something) { setStuff(something); } }
Here, before the constructor completes, final variables will be set. So why does the compiler complain about this?
noMAD
source share