In the case of the anonymous inner class this
is the anonymous class itself. To access the outer class this
from the anonymous one you need to do OuterClassName.this
.
However an inner class is allowed to access variables and methods from the outer class. Whether the inner class is anonymous or not makes no difference what-so-ever.
See:
I thought inner classes could access the outer class variables/methods?
Java nested inner class access outer class variables
This is one of the most important differences between static and non-static inner classes.
You only need the class name if (for example) you have a method with the same name in both classes so it call tell which one you mean. That's what is happening with this
, both the inner and outer class have a this
- so it defaults to the inner one unless you say otherwise.