Java无法在Map ADT接口中实现将Pair类作为其泛型参数的函数
我创建了一个具有通用函数Java无法在Map ADT接口中实现将Pair类作为其泛型参数的函数,java,dictionary,generics,interface,Java,Dictionary,Generics,Interface,我创建了一个具有通用函数entries()的映射接口 // return iterable collection of all the key-value entries in the map public ArrayList<Pair<KeyType, ValueType>> entries(); 如何解决这个问题?您可能在接口声明中留下了一个泛型绑定。由于您的Pair要求密钥彼此可比较(KeyType extensed compariable),因此您的映射需要在其
entries()
的映射接口
// return iterable collection of all the key-value entries in the map
public ArrayList<Pair<KeyType, ValueType>> entries();
如何解决这个问题?您可能在接口声明中留下了一个泛型绑定。由于您的
Pair
要求密钥彼此可比较(KeyType extensed compariable
),因此您的映射需要在其KeyType
声明中重申此界限,以便将Pair
与其密钥类型一起使用。如果Pair
对其进行绑定,则可能还需要绑定ValueType
interface Map <KeyType extends Comparable<KeyType>, ValueType> { ... }
接口映射{…}
在泛型类型擦除下,对
的键类型
被替换为可比
。如果您未绑定Map
的KeyType
,它将被替换为对象
,该对象不可分配给可比
,如果没有可能失败的缩小转换,则该对象将被替换。请发布您定义的Map界面
interface Map <KeyType extends Comparable<KeyType>, ValueType> { ... }