方法传递的参数赋值问题--堆栈的存储问题

	
	public static Object change(Object obj) {
		System.out.println(" in change method, the obj hash code is:" + obj.hashCode());
		if (obj instanceof Map) {
			((Map) obj).put("key", "1");
			//System.out.println(" in change method, after set value the 'Map' hash code is:" + obj.hashCode());
		} else if (obj instanceof Number) {
			obj = 2;
			//System.out.println(" in change method, after set value the 'Number' hash code is:" + obj.hashCode());
		} else if (obj instanceof String) {
			obj = 3;
			//System.out.println(" in change method, after set value the 'String' hash code is:" + obj.hashCode());
		}
		return obj;
	}
	
	public static Long change(Long b,Long a) {
		b = 1L;
		a = b;
		System.out.println("内部测试结果:"+a);
		return b;
	}
	
	public static int change(int a) {
		a = 1;
		System.out.println("内部测试结果:"+a);
		return a;
	}
	public static void main(String[] args) {
		Map map = new HashMap();
		System.out.println("out change method, the old 'map' hash code is:" + map.hashCode());
		map.put("key", "0");
		change(map);
		System.out.println(map.get("key"));
		
		Long l = new Long(0);
		System.out.println("out change method, the old 'l' hash code is:" + l.hashCode());
		change(l);
		System.out.println(l);
		
		String s = new String("0");
		System.out.println("out change method, the old 's' hash code is:" + s.hashCode());
		change(s);
		System.out.println(s);
		
		String as = new String("abc");
		String bs = "abc";
		String cs = "abc";
		String ds = new String("abc");
		
		System.out.println(as==bs);
		
		System.out.println(bs==cs);
		
		System.out.println(cs==ds);
		
		System.out.println(ds==as);
		
		Long la = 0L;
		Long la1 = 2L;
		change(la1,la);
		System.out.println("Long la1:"+la);
		
		Long la2 = new Long(2);
		Long change2 = change(la2,la);
		System.out.println("Long la2:"+la);
		
		int ia = 0;
		change(ia);
		System.out.println("int ia:"+ia);
	}

输出结果

out change method, the old 'map' hash code is:0
 in change method, the obj hash code is:106095
1
out change method, the old 'l' hash code is:0
 in change method, the obj hash code is:0
0
out change method, the old 's' hash code is:48
 in change method, the obj hash code is:48
0
false
true
false
false
内部测试结果:1
Long la1:0
内部测试结果:1
Long la2:0
内部测试结果:1
int ia:0

解答方案:堆栈的存储问题

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值