Is there any syntax for getting a reference to an anonymous inner class from another anonymous inner class?

Consider this case:

public class SomeClass {
    public void someMethod() {
        new SomeInterface() {
              public void someOtherMethod() {
                  new SomeOtherInterface() {
                       new someThirdMethod() {
                            //My question is about code located here.
                       }
                  };
              }
        };
    }
}

Is there any syntax for referring to an instance of an anonymous inner class represented by SomeInterface in the commented code? For SomeClass, you can do SomeClass.thisIs there an equivalent to get an implementation of SomeInterface?

If not, you can simply define the final local variable in the implementation of SomeInterface and reference it, but I'm just wondering if there really is direct language support for referring to an instance.

+5
source share
1 answer

, SomeInterface.this , , SomeInterface, .

this . ; , this , .

- :

SomeClass$1.this

SomeClass$1 cannot be resolved to a type; , , ( ) SomeClass$1.class.

this, final.

+5

All Articles