Re: Why must and must not be "final" ?
"Daniel Pitts =D0=B4=B5=C0=A3=BA
"
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".
Thanks a lot,
and you mean this restriction only effective when a inner class is
anonymouse? and not for all inner class?