类型参数 T 不在类型变量 T 的范围内(Java 泛型)

Type argument T is not within bounds of type-variable T(Java Generic)

我正在实现一个通用的 AVL 树,但我遇到了一些编译错误。

我的 AVL T 恤必须处理 Node<T> 类型的 T。

示例中类型为Eventclass.I要比较的节点

但是每种类型的数据必须以不同的方式进行比较,为此,我将比较传递给数据本身来进行比较。

我试图让节点实现可比接口和事件的相同功能Class。

我的代码结构如下:

树结构:

public class AvlTree<T extends Comparable<T>> {

private Node<T> root;

public AvlTree() {
    root = null;
}
 //other method to insert dellete operation in the tree

    }

节点结构:

public class Node<T extends Comparable<T>> implements Comparable<T> {
        private T data;
        private Node<T> left;
        private Node<T> right;

        public Node() {
        }
         @Override
        public int compareTo(T t) {
          return this.data.compareTo(t);
        }
     }

将放入节点对象的事件Class:

public class Event implements Comparable<Event>{
    private Point point;
    public Event() {
    }
    @Override
    public int compareTo(Event t) {
      return 1;
    }
    }

给我编译错误的代码是在我声明 AvlTree 时:

private  AvlTree<Node<Event>> treeOfEvents;

错误:

type argument Node<Event> is not within bounds of type-variable T
where T is a type-variable:
T extends Comparable<T> declared in class AvlTree

你的节点必须像这里一样实现 Comparable:

public class Node<T extends Comparable<T>> implements Comparable<Node<T>> {

因为你的 AvlTree 期望一些东西作为泛型类型,它为那个类型实现 Comparable