问题描述
public class PriorityQueueEntry<TimedTask,Long> extends AbstractMap.SimpleEntry<TimedTask,Long> implements Comparable<PriorityQueueEntry<TimedTask,Long>> {
public PriorityQueueEntry(TimedTask key,Long value) {
super(key,value);
}
@Override
public int compareto(PriorityQueueEntry<TimedTask,Long> o) {
((Long)getValue()).compareto((Long)o.getValue());
}
}
NetBeans 告诉我它找不到 compareto 方法。为什么我不能这样做?
解决方法
与
public class PriorityQueueEntry<TimedTask,Long> ...
您将定义一个具有两个名为 TimedTask
和 Long
的泛型参数的类。这些不是您所知道的实际类,而是泛型参数,碰巧与类 TimedTask
和 Long
具有相同的名称。根据您的需要,您可能希望删除这些通用参数或将它们重命名为常见名称,例如 E
、K
或 V
。