I have created an inner class in an inner class :
public class EnclosingClass {
public class InnerClass {
private EnclosingClass getEnclosing() {
return EnclosingClass.this;
}
public class InnerInnerClass {
private InnerClass getEnclosing() {
return InnerClass.this;
}
private EnclosingClass getEnclosingOfEnclosing() {
return EnclosingClass.this;
}
}
}
}
I have been surprised that java allows the InnerInnerClass
to access directly the EnclosingClass
. How is this code implemented internally by Java?
The InnerInnerClass
keeps two pointers (one on the InnerClass
and the other on the EnclosingClass
) or the InnerInnerClass access the EnclosingClass
through the InnerClass
?