Re: Why must and must not be "final" ?
NeoGeoSNK wrote:
I have two questions, why inner class can only access "final" argument
outside the inner class?
Similar to Daniel's comment, it's because the implementation is easier.
I believe C#2.0 takes the point of view that when you create an
anonymous delegate (like an anonymous inner class only a single method
and a more complicated type system) the variable should split in to -
with updates from the enclosing method not interacting with the
anonymous delegate code. However, the semantics of least surprise are
for the local variable to remain coherent. There are proposals that Java
SE 7 will allow this, possibly having to declare the local variable as
"public".
and why Java applet's init() method can't access any "final" fields?
It cannot assign final fields as it is not a constructor. That being the
point of final.
A better approach to organising applets (and indeed GUI code in general)
is to move the bulk of the code out from subclasses of components. You
can use constructors and final as you like in such code, without having
to conform to AWT/Swing implementation peculiarities. You can also use
the same code in JFrame, JInternalFrame, JScrollPane, etc.
Tom Hawtin