posted 17 years ago
If an inner class defined in a method accesses local variables defined in that method, then those local variables must be final. Final variables, of course, have a single value that never changes. This means you can make a copy of them at any time and you won't be able to tell that you're using a copy instead of the original. That's what happens here: copies of those final local variables are made and stored in instance variables of the inner class.
The reason for this is that the method that creates the object may return long before the object is no longer being used. Therefore, without this restriction, the object might try to access local variables that no longer existed (since local variables go away as soon as their defining method returns). By making the variables final and taking a copy when the object is created, the problem is avoided.