我搜索并发现了几个类似问题的实例,但是已经实现了明显的解决方案,所以我有点不知所措.仅供参考:这是一项家庭作业,如果重要的话.
public class Entry<K extends Comparable<K>, V> implements
Comparable<Entry<K, V>> {
protected K key;
protected V value;
protected Entry(K k, V v) {
key = k;
value = v;
}
public K key() {
return key;
}
public V value() {
return value;
}
// override toString method
// toString method should print the entry as:
// <key,value>
@Override
public String toString() {
return "<>" + key.toString() + ", " + value.toString();
}
public int compareTo(Entry<K, V> other) {
if …Run Code Online (Sandbox Code Playgroud)