Java泛型类型参数Project不在类型变量E的范围内

时间:2015-12-01 15:53:08

标签: java generics

我在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

我做错了什么?

1 个答案:

答案 0 :(得分:1)

试试这样:

public class Project implements Comparable<Project> {

  [add CompareTo method]
}