aspose file tools*
The moose likes Java in General and the fly likes regd  local inner class (method level) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
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://aspose.com/file-tools
 
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