Forums Register Login

Why method local inner class has access to only final variables of method.

+Pie Number of slices to send: Send
Hello,

I understand that method local inner class can not access non final members of the method because method variables life time will be till the time method executes and instance of inner class can live on the heap even after the method has executed. But what i don't understand is why inner class has access to final variables declared in the method.

Any reply will be helpful.

Thank you,
Ankush
+Pie Number of slices to send: Send
You mean non-final local variables. The word member always implies the variable is part of an instance.

For an answer to your question, you should read this thread:
https://coderanch.com/t/524522/java-programmer-SCJP/certification/Special-treatment-final-vaiables-method
+Pie Number of slices to send: Send
Thank you Stephan.

Yes, i mean to say non-final local variables of the method.

Link provided by you exactly answers my question and with some additional information.

Ankush

Seriously? That's what you're going with? I prefer this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2943 times.
Similar Threads
method local inner class
appliedreasoning #60
Question about Inner Class
Why can a method local inner class access a final variable
Method local Inner Class question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:16:48.