What Method local inner classes CAN and CANNOT DO section -->
Method local inner classes cannot access local variables of that method. .... ....., even after the method completes, the inner class object created within it might still be alive on the heap if a reference to it was passed into some other code which stores it in an instance variable...
I have tried declaring an instance variable of the type of method local inner class, but outside the method. It gives a compile error
Clearly, you cannot access even the type of the method local inner class outside the method in which it is declared. In the quotes it is mentioned, what if the object which is created inside the method , gets its reference passed outside the method, how is that possible when we cannot access the type of this method outside the method itself.
This means, once the method is complete, the local reference variable, to which the method local inner class object was assigned inside the method, dies when the method is complete. Thus, the object is abandoned.And if this is the case always, why , method local inner class objects cannot use the local variables which also die after the method is complete???
Am i not seeing another scenario in which the method local object can be passed out of the method ??? Please explain!! Thanks a ton!