草庐IT

CustomHashMap

全部标签

java - 继承不适用于作为泛型类型传递

考虑我的自定义扩展HashMap:publicclassCustomHashMapextendsHashMap{...}为什么这行不通,因为CustomHashMap是HashMap的子项?Map>customs=newLinkedHashMap();但这行得通:Map>customs=newLinkedHashMap();并且在将CustomHashMap添加(放入)到customsMap中时它也有效。customs.put("test",newCustomHashMap());在初始化时不指定泛型似乎很奇怪,但在其他情况下则不然。 最佳答案