I have not tried to answer WhiteFang34. This might work, but I don't understand how to do it ...
If you really want to define an extension of your inner class elsewhere than in the outer class, it would be most natural to define it as an extension of the inner class in another outer extension of your outer class as follows:
class Outer { int some_member; abstract class InnerBase { abstract void method(); } } class OuterExtendsOuter extends Outer { class InnerExtendsInner extends Outer.InnerBase { void method() { System.out.println(some_member); } } }
I don't run this code either, but it should work.
Update:
Based on the comment stream, I now compiled and executed both my code above and the WhiteFang34 code.
Both really work, but as noted in the comments of Pailo Eberman, both create two copies of the outer inside the built-in inner class.
I am going to support Pailo, and I will defend, just not trying to do it with tactics, as this is really an abuse of the inner class mechanism.
Just make your extended inner classes live inside the same outer class!
Update 2:
What happens in my code, based on checking the runtime using the debugger and when checking the output from the javap class checks, is that both InnerBase and OuterExtendsOuter$InnerExtendsInner have synthetic private final fields called this$0 . Since constructors are not explicitly defined, default constructors are used, and the code snippet
OuterExtendsOuter outer = new OuterExtendsOuter(); Outer.InnerBase inner = outer.new InnerExtendsInner();
forces these two fields to refer to outer .
In other words, Paŭlo's comment is completely correct.
InnerBase further experimentation, the same thing happens if you extend InnerBase in another inner class outer , so it has little to do with being defined in the same outer class or its extension, but it is in fact how non-static inner classes are usually processed.
I suspect this is documented somewhere, but I have not seen it.
Perhaps it's best to mix inheritance and inner classes as little as possible!