对于一个类的任务,我们不能使用任何语言bultin类型,所以我坚持我自己的列表。总之,这里的情况:Java如何不接受通用中的LinkedList,但接受它自己的?
public class CrazyStructure <T extends Comparable<? super T>> {
MyLinkedList<MyTree<T>> trees; //error: type parameter MyTree is not within its bound
}
但是:
public class CrazyStructure <T extends Comparable<? super T>> {
LinkedList<MyTree<T>> trees;
}
作品。 MyTree实现了Comparable接口,但MyLinkedList没有。但是,根据this,Java的LinkedList也没有实现它。那么问题是怎么解决的?
MyLinkedList:
public class MyLinkedList<T extends Comparable<? super T>> {
private class Node<T> {
private Node<T> next;
private T data;
protected Node();
protected Node(final T value);
}
Node<T> firstNode;
public MyLinkedList();
public MyLinkedList(T value);
//calls node1.value.compareTo(node2.value)
private int compareElements(final Node<T> node1, final Node<T> node2);
public void insert(T value);
public void remove(T value);
}
MyTree:
public class LeftistTree<T extends Comparable<? super T>>
implements Comparable {
private class Node<T> {
private Node<T> left, right;
private T data;
private int dist;
protected Node();
protected Node(final T value);
}
private Node<T> root;
public LeftistTree();
public LeftistTree(final T value);
public Node getRoot();
//calls node1.value.compareTo(node2.value)
private int compareElements(final Node node1, final Node node2);
private Node<T> merge(Node node1, Node node2);
public void insert(final T value);
public T extractMin();
public int compareTo(final Object param);
}
我们可以看到你的MyLinkedList定义吗? – OscarRyz 2010-05-06 22:02:31
更好地向我们展示MyLinkedList和MyTree的声明。 – bmargulies 2010-05-06 22:03:00
编辑方法签名,我可以发布其余的,如果你想 – 2010-05-06 22:32:02