我创建了具有通用函数entries()
的地图接口。Java无法在Map ADT接口中实现以Pair类作为其通用参数的函数
// return iterable collection of all the key-value entries in the map
public ArrayList<Pair<KeyType, ValueType>> entries();
的问题是,当我尝试实现我在entries()
功能得到在接口文件这个错误接口:Bound mismatch: The type KeyType is not a valid substitute for the bounded parameter <KeyType extends Comparable<KeyType>> of the type Pair<KeyType,ValueType>
我该功能的实现如下所示:
public ArrayList<Pair<KeyType, ValueType>> entries(){
ArrayList<Pair<KeyType, ValueType>> list = new ArrayList<Pair<KeyType, ValueType>>();
preorderList (root, list);
return list;
}
我该如何解决这个问题?
请发布您定义的地图界面 –