This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes regd  local inner class (method level) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "regd  local inner class (method level)" Watch "regd  local inner class (method level)" New topic
Author

regd local inner class (method level)

Ramakrishnan Ponmudi
Ranch Hand

Joined: Apr 20, 2004
Posts: 72
why final local variables are only accessed by local inner class
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
The instance of the anonymous class may live longer than the method, and therefore longer than the local variable. To circumvent this live time problem, the instance actually gets a *copy* of the local variable. If you were allowed to change the local variable, that could lead to confusing inconsitencies between the original and the copy inside the instance of the anonymous class. Therefore you are not allowed to change the value of the local variable - it needs to be final.

Does that help?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Ramakrishnan",
Unfortunately your display name is not valid.

We require display names to be two words: Your first name, a space, then your last name. Fictitious names are not allowed.

I have already warned you here. Please change it immediately since accounts with invalid display names get deleted, sometimes without warning.

thanks,
Dave.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: regd local inner class (method level)
 
Similar Threads
instantiating class issue
Inner Classes
Inner class
Method Local inner class
method-local inner class object cannot use the local variables