如果我定义了Map<K,V> map = new HashMap<K, V>()
为什么我不能这样做:
map.put(new MyKey<CustomObject>(), new SomeOtherObject<CustomObject>());
但是,如果我通过另一种方法来做到这一点,它会起作用,即:
add(new MyKey<CustomObject>(), new SomeOtherObject<CustomObject>());
public <K, V> void add(K k, V v){
Map<K, V> threadLocalMap = new HashMap<K, V>();
threadLocalMap.put(k, v);
}