Hi everybody. I want to know that why the inner class object cannot use the local variables of the method the inner class is in?? I know that local variables of the method live on the stack and exisist only for the lifetime of the method. But in this following code the life time of the main method() exisist through out the inner class ends then it is not compiling. Here is the code
But in this following code the life time of the main method() exisist through out the inner class ends then it is not compiling.
Yes, but you are assuming that the compiler has special code to detect whether any instances of the inner class escapes the method. Maybe in future versions of Java, this will be added -- but currently no. So currently, accessing local variables (which are not final) is not allowed.
I am very sorry Henry i am not able to make out what exactly you are telling me can you please explain this a bit briefly. Also can you expalin me why a inner class can't be public,private or static but it could be final and abstract.