我的意思是,當我們從該函數返回時,數組的地址與我們輸入函數之前的地址保持相同。 一個例子:Java:爲什麼在函數中改變數組的地址,當我們從函數返回時,不改變它的地址?
class sdasd {
public static void main(String[] args){
int[] obj = new int [7];
//obj has an address
sdasd t = new sdasd();
t.func(obj);
//obj has the same address as before!!
}
void func(int[] obj){
int[] otherObj = new int[13];
obj=otherObj;``
//we changed the address of the array 'obj'?
}
}
感謝幫助
您試圖更改值的值,因爲它是按值傳遞的。 – 2013-03-18 16:26:18