为什么这段代码有效?
public class Final {
public final int[][] arr = new int[2][];
Final(){
arr[0] = new int[4];
arr[0] = new int[5];
arr[1] = new int[4];
}
public static void main(String[] args) {
Final fi = new Final();
System.out.println(fi.arr[0].length);
System.out.println(fi.arr[1].length);
}
}
而以下不起作用(我认为这是正确的)。
public class Final {
public final int[] arr;
Final(){
arr = new int[4];
arr = new int[5];
}
public static void main(String[] args) {
Final fi = new Final();
System.out.println(fi.arr.length);
}
}
声明何时final
“开始”?