引用参数传递(call-by-reference parameter passing)
打印结果:
Test[3,4]
Test[3,4]
null
public class Test {
public int a ;
public int b ;
@Override
public String toString() {
// TODO Auto-generated method stub
return this.getClass().getSimpleName()+"["+a+","+b+"]";
}
}
public static Test changeTest(Test test){
test.b = 4;
test = null;
return test;
}
public static void testCallByReferenceParameterPassing(){
Test t = new Test();
t.a = 1;
t.b = 2;
Test t2 = t;
t2.a = 3;
Test t3 = changeTest(t);
System.out.println(t);
System.out.println(t2);
System.out.println(t3);
}
打印结果:
Test[3,4]
Test[3,4]
null
984

被折叠的 条评论
为什么被折叠?



