`
txidol
  • 浏览: 52377 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论
阅读更多
引用参数传递(call-by-reference parameter passing)
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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics