2012-06-17 69 views
0

我有以下接口:如何實現:接口MySortedCollection <T延伸可比<T>>

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{ 

怎麼了?

回答

5

應該

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

確保AVLNode類具有相似的簽名

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

shoudl是

public class AVLTree<T extends Comparable<T>> implements MySortedCollection<T> { 
相關問題