Re: Why must and must not be "final" ?
NeoGeoSNK wrote:
Hello,
I have two questions, why inner class can only access "final" argument
outside the inner class?
and why Java applet's init() method can't access any "final" fields?
example:
public class AppletGui extends JApplet {
.........
final JTextField textvalue;
..........
public void init(){
..........
textvalue = new JTextField(25); //this will
encounter a compiled time error "the final field AppletGui.textvalue
can not be assigned
}
}
any suggestions are appreciated. ^ ^
Thanks
NeoGeoSnk
Its purely to reenforce to the programmer what really is happening.
The value of your parameters/variables which are used in your
anonymouse class are copied at the time that the object is created
(they are actually hidden final fields, I believe). If you were to
change the value later, that would be more confusing than having to
know that they are just "final".