Java 泛型类型参数项目不在类型变量 E 的范围内
Java generics type argument Project is not within bounds of type-variable E
我在使用 java 泛型时遇到问题,这些泛型不允许我初始化 AVLTree 变量。
AVLTree class:
public class AVLTree<E extends Comparable<E>> extends BSTTree<E> {...}
BSTTree Class 和节点:
public class BSTTree<E extends Comparable<E>> {...
protected static class Node<E extends Comparable<E>> implements Comparable<Node<E>>{...}}
项目Class:
public class Project {
private String title;
public Project(String title){
this.title=title;
}
}
当我尝试执行以下操作时:
private AVLTree<Project> projectTree;
我收到一条错误消息:
type argument Project is not within bounds of type-variable E where E is a type variable:
E extends Comparable<E> declared in class AVLTree
我做错了什么?
这样试试:
public class Project implements Comparable<Project> {
[add CompareTo method]
}
我在使用 java 泛型时遇到问题,这些泛型不允许我初始化 AVLTree 变量。
AVLTree class:
public class AVLTree<E extends Comparable<E>> extends BSTTree<E> {...}
BSTTree Class 和节点:
public class BSTTree<E extends Comparable<E>> {...
protected static class Node<E extends Comparable<E>> implements Comparable<Node<E>>{...}}
项目Class:
public class Project {
private String title;
public Project(String title){
this.title=title;
}
}
当我尝试执行以下操作时:
private AVLTree<Project> projectTree;
我收到一条错误消息:
type argument Project is not within bounds of type-variable E where E is a type variable:
E extends Comparable<E> declared in class AVLTree
我做错了什么?
这样试试:
public class Project implements Comparable<Project> {
[add CompareTo method]
}