我在閱讀有關複製參考數組的信息。複製參考數組
Object[] obj1 = {new Integer(11),
new StringBuffer("foobar"),
new Double(12.95)};
Object[] obj2 = new Object[obj1.length];
for(int i = 0; i < obj1.length; i ++)
obj2[i] = obj1[i];
//this change to obj1 does NOT effect obj2.
obj1[0] = new Integer(5);
System.out.println(Arrays.toString(obj1));
System.out.println(Arrays.toString(obj2));
System.out.println();
//this change to obj1 DOES effect obj2
((StringBuffer) obj1[1]).append('s');
System.out.println(Arrays.toString(obj1));
System.out.println(Arrays.toString(obj2));
都指向相同的元素,但改變元件改變第二種情況第2個數組沒有在第一case.Can有人能解釋我爲什麼不改變它第二陣列中的第一種情況下這裏的陣列。