今日面接を受けて、次の Java コードを入手しました。
public class Question_6 {
public static void main(String[] args){
Map<Integer,String> map1 = new HashMap<Integer,String>();
map1.put(new Integer(1),"001a");
map1.put(new Integer(1),"001b");
map1.put(new Integer(2),"002");
System.out.println(map1.size());
Map<MyInt,String> map2 = new HashMap<MyInt,String>();
map2.put(new MyInt(1),"001a");
map2.put(new MyInt(1),"001b");
map2.put(new MyInt(2),"002");
System.out.println(map2.size());
}
}
public class MyInt {
int i;
public MyInt(int i) {
this.i = i;
}
}
質問は次のとおりです。
コンソールには何が出力されますか?
問題の解決策を提案します。
最初の質問に対する答えは次のとおりです。
2
3
しかし、私は理由を知りませんか?何が問題なのMyInt
ですか?