In Java, we can initialize the final field in the constructors in both the base class and its subclasses, as well as in the built-in initialization block in the base class. However, it seems that we cannot initialize the final fields in the inline initialization block in the subclass. This behavior mainly affects anonymous classes from which super constructors cannot be called.
abstract class MyTest { final protected int field; public MyTest() {
MyTest anonymTest = new MyTest() { {
Is there a way to initialize the final inherited field in the anonymous class?
Comment This question does not concern constructors, but the final field initialization.
java inheritance final
Dávid Horváth Apr 04 '16 at 19:20 2016-04-04 19:20
source share