Mapにはオブジェクトのリファレンスが格納されています

1358 ワード

public class Main {

    public static void main(String[] args) {

        Map< Integer, Stu> mapA=new HashMap<Integer, Stu>();

        Map<String, Stu> mapB=new HashMap<String, Stu>();

        Stu stu=new Stu();

        stu.x=10;

        stu.y=10;

        mapA.put(1, stu);

        mapB.put("1", stu);

        System.out.println(mapA.get(1).x);

        stu.x=5;

        System.out.println(mapB.get("1").x);

        System.out.println(mapA.get(1).equals(mapB.get("1")));

    }

出力105 true