java研究一个简单的算法碰到这种输出,哎,以前还真没注意还能这样......

java研究一个简单的算法碰到这种输出,哎,以前还真没注意还能这样......

求大神指定这种运行原理叫什么?????

package org.rui.util;

import java.util.HashMap;
import java.util.Map;

public class A
{

	public static void main(String[] args)
	{
		Map<String, String> m = new HashMap<String, String>();
		Map m2 = m;
		m2.put("a", "ava");
		System.out.println(m);

		
		//
		B b = new B();
		B b2 = b;
		b2.setId(100);
		b2.setName("abc");
		
		b.setId(50);
		
		B b3=b2;
		b3.setName("B3");
		System.out.println(b);
		System.out.println(b2);
		System.out.println(b3);

	}

}
/***
 * output:
{a=ava}
B [id=50, name=B3]
B [id=50, name=B3]
B [id=50, name=B3]
 */

package org.rui.util;

import java.util.HashMap;
import java.util.Map;

public class B
{
	private Integer id;
	private String name;

	public Integer getId()
	{
		return id;
	}

	public void setId(Integer id)
	{
		this.id = id;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	@Override
	public String toString()
	{
		return "B [id=" + id + ", name=" + name + "]";
	}
	
	
	public static void main(String[] args)
	{
		
		Map m=new HashMap();
		Map m2=m;
		m2.put("m2","m2v");
		
	    Map<String,String> m3=null;
	    
		System.out.println("---------------------------------");
		
		m3=new HashMap<String,String>();
		m3.put("m3_1", "m3v_1");
		m2.put("m2add3_1", m3);		
		m2=m3;
		
		System.out.println("m:"+m);
		System.out.println("m2:"+m2);
		System.out.println("m3:"+m3);
		System.out.println("---------------------------------");
		
		m3=new HashMap<String,String>();
		m3.put("m3_2", "m3v_2");
		m2.put("m2add3_2", m3);	
		System.out.println("m2xx:"+m2);
		m2=m3;
		
		
		System.out.println("m:"+m);
		System.out.println("m2:"+m2);
		System.out.println("m3:"+m3);
		
		
		
		
	}
	

}
/***output:
 ---------------------------------
m:{m2add3_1={m3_1=m3v_1}, m2=m2v}
m2:{m3_1=m3v_1}
m3:{m3_1=m3v_1}
---------------------------------
m2xx:{m2add3_2={m3_2=m3v_2}, m3_1=m3v_1}
m:{m2add3_1={m2add3_2={m3_2=m3v_2}, m3_1=m3v_1}, m2=m2v}
m2:{m3_2=m3v_2}
m3:{m3_2=m3v_2}

 */


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值