数组传递
希望在哪 2014-09-04 10:26:06 public class test {
public static void main(String[] args){
test t = new test();
int[] A = {1,2,3};
t.change(A);
System.out.println(A[0]+" "+A[1]+" "+A[2]);
}
void change(int[] A){
int[] B = {1,1,1};
A=B; // 1
A= null; // 2
A[0] = 3; // 3
}
}
上面代码情况1输出[1,2,3],情况2输出[1,2,3],情况3输出[3,2,3],数组传递应该传引用才是啊,所以我觉得只有情况3才是正常的。不明白为什么情况1,2不改变数组A