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> { ... }