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.
why final local variables are only accessed by local inner class
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
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