• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

About inner classes....

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inner class declared within a method cannot access the method's local variable....But if the method's local variable is declared 'final',then it can be accessed by the inner class...... Any reason for this behaviour?!
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Because accessing local variable in the "local class" (inner class declaring in the method) is converted by passing parameters to the local class constructor (and saved in the hidden field).

If local variable were not final, something like "b=b+1" couldn't affect local class field, and the code wouldn't run what we intended.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!