Hi all,
Krep wrote:
my guess is that final only locks the reference
Good guess. Marking a primitive variable final means, that it's value has to be assigned once and for all. It cannot be changed afterwards.
Marking an object variable final means, that it cannot be reassigned to another variable. But the object the variable is pointing to may be changed.
See example:
And as Ernest already mentioned: "this whole thing with anonymous inner classes".
A method local inner class can only refer to local variables if they are final.
See second example:
The depicted line will only compile, if variable
year is final.
And that may be the cause why your JButton is marked final, as in GUI codes anonymous inner classes are frequently used e.g. for action listeners.
Yours,
Bu.