1
public class Test { public static void main(String[] args) { final int num1[] = {1,2,3,4,5}; num1[1] = 5; System.out.println(num1[1]); }}报错代码:
public class Test { public static void main(String[] args) { final int num1[] = {1,2,3,4,5}; int num2[] = {1,2,3,4,5,6}; num1 = num2; }}final int num1[]只是说你的num1数组不能再指向其他数组对象,
但它指向的数组的内容是可以变的!
java中的常量永远不能修饰对象的实际内容。
即:final int b[2]={1,2};
b[1]++; //OK
b = new int(){1,2}; //NOT OK
int b[2]={1,2};
b[1]++; //OK
b = new int(){1,2}; //OK