若將 Final class A = new ClassA()
則 classA 就被 bond 住, 不行將 classA assign 到其於 ClassA instance.
{{{
import andy.Point;
public class Finaltest {
public static void main(String[] args) {
final Point pa = new Point();
pa.x = 10;
pa.y = 11;
System.out.println("pa.x:" + pa.x + ", pa.y" + pa.y);
pa.x = 15;
// Not correct
pa = new Point();
}
}}}
{{{
[Andy@t-ap188 row]$ javac Finaltest.java
Finaltest.java:12: cannot assign a value to final variable pa
pa = new Point();
^
1 error
[Andy@t-ap18
}}}
沒有留言:
張貼留言