I have the following case of inner classes.
class Outer {
private class Inner1 extends InnerBase {
}
private class Inner2 extends InnerBase {
}
private class InnerBase {
}
}
Usually I considered an inner class to have an additional, hidden “this” to the outer class.
However, but what will happen is the inner class is derived from an other inner class?
All inner classes (Inner1, Inner2, InnerBase) should have an additional this.
Will Inner1, Inner2 have own references to outer this ?
Or just reusing the one from InnerBase, causing a slightly different behavior?
(Hidden this == a reference pointing to the instance of outer class)
Internally each non-static inner class in the hierarchy will have its own reference to
this. You can confirm it withjavapBTW, if you really want, you can exploit some obscure java syntax to have different values for the
this$0member between the parent and child class. Here’s how:Running the program you get: