0
我试图使用compareTo方法通用节点类型E.获得当实现接口相当的编译错误
我已经结合E至可比
public class LinkedList<E extends Comparable<E>> {
// ----------------------------------------------------------
// Implementing the doubly linked nodes (static nested class)
// ----------------------------------------------------------
private static class Node<E extends Comparable<E>> {
这种方法isSorted是内实现LinkedList类中,Node类位于Linkedlist类中。
我不断收到编译错误“的方法的compareTo(LinkedList.Node)是未定义的类型LinkedList.Node”
我相信,只有弹出当E是不延长媲美,我的情况下, 。 有什么帮助吗?
public boolean isSorted(){
if(!isEmpty()){
Node<E> temp = head;
boolean local = true;
int x=0;
while (temp.next != null){
x=temp.compareTo(temp.next);
if(x<0){
temp = temp.next;}
else {return local;}
}
return local;}
else{ throw new IllegalArgumentException();}
}
我检查这个线程已经,How to compare generic nodes in a linked list using Comparable?
它并没有帮助。
预先感谢您
Mjall2
我感觉有多厚...... – Mjall2 2012-04-10 00:48:56