The thing that bothers me is the second point.
I thought it might have to do with the fact that the "this" pointer isn't static and so the inner class can't access it. I'm not sure if that's the right explanation though.
This also raised another question for me which was "where is the "this" pointer defined?"
The difference between a
static
nested class and one that isn'tstatic
is precisely that an instance of a non-static
inner class is associated with a specific instance of the enclosing class, while astatic
inner class isn't. There is noA.this
for an instance of astatic
inner class to be associated with.If an inner class is
static
then it can be instantiated without an enclosing instance of the outer class. For a non-static
inner class an instance of the outer class is required for instantiation. For example, if your class structure is this :then to instantiate
B
andC
you would have to do it like this :Behind the scenes when a non-
static
inner class is instantiated an instance of the enclosing class is passed into the constructor. The instance ofOuterClass.this
is then accessible because of this.To verify the "behind the scenes" thing you can check the declared constructors and declared fields of the inner class via reflection: