Java 在父类的参数扩展类的情况下扩展类
我试图将TreeMap的一个版本扩展为一个子类,以便更有效地索引单词,但我不确定正确的语法是什么。树映射的类定义如下所示Java 在父类的参数扩展类的情况下扩展类,java,generics,inheritance,comparable,Java,Generics,Inheritance,Comparable,我试图将TreeMap的一个版本扩展为一个子类,以便更有效地索引单词,但我不确定正确的语法是什么。树映射的类定义如下所示 public class MyTreeMap<K extends Comparable<? super K>,V> extends AbstractMap<K,V> { 公共类MyTreeMap 否则,您试图将子类型声明为不具有限制,这是编译错误“绑定不匹配” 您尝试的几乎是正确的,绑定只需要在泛型类型声明中,而不是传递给超类的参数中 p
public class MyTreeMap<K extends Comparable<? super K>,V> extends AbstractMap<K,V> {
公共类MyTreeMap
否则,您试图将子类型声明为不具有限制,这是编译错误“绑定不匹配”
您尝试的几乎是正确的,绑定只需要在泛型类型声明中,而不是传递给超类的参数中
public class TreeMapIndexer<K> extends MyTreeMap<K,LinkedList<Integer>> {
public class TreeMapIndexer<K> extends
MyTreeMap<K extends Comparable<? super K>, LinkedList<Integer>> {
public class TreeMapIndexer<K> extends
MyTreeMap<K, K extends Comparable<? super K>, LinkedList<Integer>> {
class MyTreeMap<K extends Comparable<? super K>, V>
extends AbstractMap<K, V>
class TreeMapIndexer<K extends Comparable<? super K>>
extends MyTreeMap<K, LinkedList<Integer>>