Dro*_*der 0 java interface comparable
我有以下界面:
interface MySortedCollection<T extends Comparable<T>> {
boolean isElement(T t);
void insert(T t);
void printSorted();
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用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(){}
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误:
error: AVLTree is not abstract and does not override abstract
method insert(Comparable) in MySortedCollection
public class AVLTree<T> implements MySortedCollection{
Run Code Online (Sandbox Code Playgroud)
怎么了?
它应该是
public class AVLTree<T extends Comparable<T>> implements MySortedCollection<T> {
}
Run Code Online (Sandbox Code Playgroud)
确保AVLNode类具有类似的签名
public class AVLNode<T extends Comparable<T>> {
}
Run Code Online (Sandbox Code Playgroud)