Declaring a final method variable means that its value cannot change; that it can only be installed once. How is this applicable in this context?
I have been aware of this limitation with anonymous classes for some time, but I never understood why. I see that no one still makes any of the answers so far. some googling climbed lower, which, I think, explains this well.
An anonymous local class can use local variables because the compiler automatically gives class a a private instance field to store a copy of each local variable used by the class. The compiler also adds hidden parameters to each constructor to initialize these automatically created private fields. Thus, the local class is not really variables, but just their own copies. The only way this can work correctly is if the variables are declared final so that they are guaranteed not to change. Given this guarantee, the local class is confident that its internal copies of the variables accurately reflect the actual local variables.
loan for: http://renaud.waldura.com/doc/java/final-keyword.shtml#vars
Of course, something that I think the compiler really should be hiding from the developers is not obvious either.
Jeff
source share