• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Ankush Kanungo
Greenhorn
Posts: 10
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stephan van Hulst
Saloon Keeper
Posts: 7932
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
http://www.coderanch.com/t/524522/java-programmer-SCJP/certification/Special-treatment-final-vaiables-method
 
Ankush Kanungo
Greenhorn
Posts: 10
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!