-1
我想知道为什么输出仍然为1,2,3,4,5
,因为如果我更改doIt
(例如:z[0] = 10
)中的值,则数组会发生更改。Java数组通过引用
public class Main
{
public static void main(String[] args) {
int[] array = {0,1,2,3,4,5};
testIt.doIt(array);
for(int i=0;i<array.length;i++){
System.out.println(array[i]);
}
}
}
class testIt
{
public static void doIt(int [] z){
z = null
}
}
阅读本文http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value/40523#40523 – 2014-10-22 06:39:50