Hi, As we know method local inner class can a) Access the instance variables of outer class[ This is usual for any type of inner class] b) Cannot access local variables of method in which its defined [because local variables live in stack and die after method exceution] Howeve method local inner class can access final local variables declared in the method, in which the class is defined. Does this mean, that final local variables a) Live in heap and not in stack, even when they are local variables? b) If they live in heap why cant we access these variables from some other methods?, Why can we access them from method local inner class, As method local inner class object can still live even after method terminates. Hope my question is clear. Thanks Deepak
Ohhh, Thats the reason only final local variables and local variable can be accessed from method local inner class, because they are final and cannot be modified so JVM will simply copy the value for the final variables. And yes final local variables live in stack and not in heap.
After thinking for a while i understood why this behavior is done only for final and not local variables.
SCJP, SCWCD, SCBCD
In the renaissance, how big were the dinosaurs? Did you have tiny ads?