0

我有以下界面:

interface MySortedCollection<T extends Comparable<T>> {
    boolean isElement(T t);
    void insert(T t);
    void printSorted();
}

我尝试使用 AVLTree 来实现接口:

public class AVLTree<T> implements MySortedCollection{

  private AVLNode<T> tree=null;

  public AVLTree (){
  } 

  public boolean isElement(T t){

  }


  public void insert(T t){
    if(tree==null){
      tree= new AVLNode<T>(t);
    }
  }

  public void printSorted(){}

}

但我得到了错误:

error: AVLTree is not abstract and does not override abstract
method insert(Comparable) in MySortedCollection 
public class AVLTree<T> implements MySortedCollection{

怎么了?

4

2 回答 2

5

它应该是

public class AVLTree<T extends Comparable<T>> implements MySortedCollection<T> {
}

确保 AVLNode 类具有相似的签名

public class AVLNode<T extends Comparable<T>> {
}
于 2012-06-17T16:41:40.560 回答
0

应该是

public class AVLTree<T extends Comparable<T>> implements MySortedCollection<T> {
于 2012-06-17T16:41:02.357 回答