我在java泛型方面遇到麻烦,不允许我初始化AVLTree变量。
AVLTree课程:
public class AVLTree<E extends Comparable<E>> extends BSTTree<E> {...}
BSTTree类和节点:
public class BSTTree<E extends Comparable<E>> {...
protected static class Node<E extends Comparable<E>> implements Comparable<Node<E>>{...}}
项目类:
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
我做错了什么?
答案 0 :(得分:1)
试试这样:
public class Project implements Comparable<Project> {
[add CompareTo method]
}