私は次のクラスを持っています:
public class IntegerKey extends Number implements Comparable<IntegerKey> {
private Integer m_key;
public IntegerKey(Integer key) {
m_key = key;
}
public IntegerKey(int key) {
m_key = key;
}
}
このクラスを次のように使用したいと思います:
次のジェネリックがあるとします。
Map<IntegerKey, MyCache> map = new HashMap<IntegerKey, MyCache>();
map.put(5, new MyCache());
これはコンパイルされません。なぜですか?? 私はしたくない:
map.put(new IntegerKey(5), new MyCache());
ありがとうございました。