I was reading inner classes and i found out that for every outer class variable ,a static function gets defined by the compiler that is responsible for the inner classes having access to outer class variables.Here is an example:
import static java.lang.System.*;
now when we run javap -private A
we see a compiler defined method as:
static boolean access$0(A);
now when the following statement is written:
it is converted into
now if the function is static why doesn't the compiler use the classname too since that is how you call the static method that is it should have been :
The inner class instance always contains a reference to the instance of outer class that was used to create the instance of the inner class; this reference is used to call methods and access members of the outer class. You can explicitly access reference to the outer class using OuterClass.this (where OuterClass is the name of the outer class).
There is not any special privilege involved actually. If you implement a static inner class and keep the reference to the outer instance in it, you can implement all of the functionality of non-static inner classes. The built-in solution just lets you do the same with less work and less code.