There is an abstract class that has a public void SomeMethod() {} method public void SomeMethod() {} How, when declaring a class object, call this method from override?

 private static void AbstrClassInit() { Dialog abstrClass = null; // Если тут final, то (1), если нет (2) abstrClass = new AbstrClass() { //(1) Cannot assign a value to final variable @Override public void EscapeAction() { abstrClass.SomeMethod(); //(2) Variable 'abstrClass' is accesed from within inner class, needs to be declared final }; } 

    1 answer 1

    You initially initialize the variable to null after this, if it is final, it cannot be reinitialized. Thus, you need to immediately initialize the variable with an instance of the class and make it final for access from the inner class.

    At the same time, you try to call the method of its instance when defining a class ... You are doing something wrong. You just need to call the method through this , which is a link to an instance of your class.

     private static void AbstrClassInit() { final Dialog abstrClass = new AbstrClass() { @Override public void EscapeAction() { this.SomeMethod(); }; }