简体   繁体   English

如何实现:接口MySortedCollection <T extends Comparable<T> &gt;

[英]How to implement: interface MySortedCollection<T extends Comparable<T>>

I have the following interface: 我有以下界面:

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

I tried to use the AVLTree to implement the interface: 我尝试使用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(){}

}

But I got the error: 但是我得到了错误:

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

What's wrong? 怎么了?

It should be 它应该是

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

Make sure that AVLNode class has a similar signature 确保AVLNode类具有相似的签名

public class AVLNode<T extends Comparable<T>> {
}

应该

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM