• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 10
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 14499
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
https://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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
reply
    Bookmark Topic Watch Topic
  • New Topic