Reputation: 809
Having the following code:
public class Main {
private Main() {}
class Test extends Main {
{
System.out.printf("This: %h\nEnclosed in: %h\n",
this, Main.this);
System.out.printf("Main.this is instance of %s\n\n" ,
Main.this.getClass());
}
}
public static strictfp void main(String... args) {
new Main().new Test();
}
}
Here are the questions:
Upvotes: 0
Views: 95
Reputation: 13374
Think of the non-static inner class as something similar to:
public class Main {
static class Test extends Main {
private final Main _outer;
...
}
}
Where the _outer
reference is established during construction. At the GC level, instances of outer and inner class are not differentiated at all.
Upvotes: 3