Java extends命令上的错误消息,但我不知道原因

Java extends命令上的错误消息,但我不知道原因,java,binary-tree,nodes,Java,Binary Tree,Nodes,我尝试实现一个接口,在接口的泛型中,我扩展了Comparable。出于某种原因,这会导致出现错误消息,但我不知道原因 public类BinTreeGen实现bintreegenterface{} 这是两个错误:这一行有多个标记 -标记“>>”上出现语法错误,应在该标记之后出现{ 代币 -标记“扩展”上的语法错误,应为 界面中的代码: public interface BinTreeGenInterface<E extends Comparable<E>> { /*

我尝试实现一个接口,在接口的泛型中,我扩展了Comparable。出于某种原因,这会导致出现错误消息,但我不知道原因

public类BinTreeGen实现bintreegenterface{}

这是两个错误:这一行有多个标记 -标记“>>”上出现语法错误,应在该标记之后出现{ 代币 -标记“扩展”上的语法错误,应为

界面中的代码:

public interface BinTreeGenInterface<E extends Comparable<E>> {
    /**
     * counts all nodes in the subtree of k (inclusive k)
     * @param k given node
     * @return number of nodes in the subtree of k
     */
    public abstract int countNodes(BinNodeGen<E> k);
    
    /**
     * counts all nodes in the tree
     * @return number of nodes
     */
    public abstract int countNodes();
    
    /**
     * inserts an item into a sorted subtree if the item does not already exist 
     * and returns true, if the item was successfully inserted
     * @param item to be inserted
     * @return true, if item was successfully inserted
     */
    public abstract boolean insertNode(E item);
    
    /**
     * searches for an item in a sorted subtree
     * @param item to search for 
     * @return node with the searches item
     */
    public abstract BinNodeGen<E> find(E item);

    /**
     * returns all nodes of the subtree of k as a String
     * @param k given node
     * @return String representation of the subtree of k
     */
    public abstract String toString(BinNodeGen<E> k);
    
    /**
     * returns all nodes of the tree as a String
     * @return String representation of the tree
     */
    public abstract String toString();

}
公共接口BintreeGenterface{
/**
*计算k(包括k)子树中的所有节点
*@param k给定节点
*@返回k的子树中的节点数
*/
公共抽象int countNodes(BinNodeGen k);
/**
*对树中的所有节点进行计数
*@返回节点数
*/
公共抽象int countNodes();
/**
*如果项不存在,则将该项插入已排序子树
*如果项目已成功插入,则返回true
*@param要插入的项目
*@return true,如果项目已成功插入
*/
公共抽象布尔插入节点(E项);
/**
*在已排序子树中搜索项
*@param要搜索的项目
*@return节点与搜索项
*/
公开摘要BinNodeGen find(E项);
/**
*以字符串形式返回k的子树的所有节点
*@param k给定节点
*@return表示k的子树的字符串
*/
公共抽象字符串toString(BinNodeGen k);
/**
*以字符串形式返回树的所有节点
*@返回树的字符串表示形式
*/
公共抽象字符串toString();
}
我试图在BinTreeGen类中实现以下代码:

public class BinTreeGen<T> implements BinTreeGenInterface<E extends Comparable<E>>{
    
    /**
     * 
     * Klasse zum erstellen eines Binaerknotens
     *
     */
    class BinNodeGen<B>{
        private B data;
        private B left, right;
        
        public B getData() {
            return data;
        }

        public void setData(B data) {
            this.data = data;
        }

        public B getLeft() {
            return left;
        }

        public void setLeft(B left) {
            this.left = left;
        }

        public B getRight() {
            return right;
        }

        public void setRight(B right) {
            this.right = right;
        }

        /**
         * Konstruktor BinNode
         * @param d übernimmt einen int Wert welcher den Inhalt eines Knoten zuschreiben soll
         */
         BinNodeGen(B d) {
            data = d;
            left = right = null;
        }
        
        /**
         * zusaetzlicher Konsruktor um Knoten direkt zu erzeugen
         * @param d uebernimmt einen int Wert welcher den Inhalt eines Knoten zuschreiben soll
         * @param l uebernimmt den Wert für einen Kindsknoten links
         * @param r uebernimmt den Wert für einen Kindsknoten rechts
         */
        BinNodeGen(B d,B l, B r) {
            data = d; left = l; right = r;
        }
    }
    
    private BinNodeGen<B> root = null;
    
    /**
     * Konstruktor für BinNode
     * @return 
     */
    void BinTree() {
        root = null;
    }
    
    /**
     * zusaetzlicher Konsruktor um Binaerbaum direkt zu erzeugen
     * @param rn bekommt Binaeknoeten uebergeben aus denen ein Binaerbaum gebildet wird
     */
    BinTree(BinNode rn) {
        root = rn;
    }
    
    
    
}
public类BinTreeGen实现bintreegenterface{
/**
* 
*Klasse zum erstellen和Binarknotens
*
*/
宾诺德根类{
私人B数据;
二等兵B左,右;
公共B getData(){
返回数据;
}
公共无效设置数据(B数据){
这个数据=数据;
}
公共B getLeft(){
左转;
}
公共无效设置左(B左){
this.left=左;
}
公共B getRight(){
返还权;
}
公共无效设置权(B权){
这个。右=右;
}
/**
*Konstruktor BinNode
*@param dübernimt ein int Wert welcher den in healt eines Knoten zuschreiben soll
*/
宾诺德根(丁){
数据=d;
左=右=空;
}
/**
*祖萨埃茨利彻·科斯鲁克托是一位伟大的领袖
*她是一个很有前途的人
*@param l uebernimmt den Wert für einen Kindsknoten链接
*@param r uebernimmt den Wert für einen Kindsknoten rechts
*/
宾诺德根(bd,bl,br){
数据=d;左=l;右=r;
}
}
私有BinNodeGen root=null;
/**
*康斯特鲁克托尔宾诺德酒店
*@返回
*/
void BinTree(){
root=null;
}
/**
*这是一个非常重要的问题
*@param rn bekommt binaeknoten uebergen aus denen in Binaerbaum gebildet wird
*/
BinTree(BinNode rn){
根=rn;
}
}

(我知道它充满了bug)

首先,你的类BinTreeGen的头是错误的,因此你得到了错误“绑定不匹配”!!! 您的类标题是:

public类BinTreeGen实现bintreegenterface{..}

您应该将其更改为:

public类BinNodeGen实现bintreegenterface{..}


类BinNodeGen中的泛型T是Comparable的子类。您可以在接口bintreegenterface中使用T。首先,类BinTreeGen的头是错误的,因此您会得到错误“绑定不匹配”!!! 您的类标题是:

public类BinTreeGen实现bintreegenterface{..}

您应该将其更改为:

public类BinNodeGen实现bintreegenterface{..}


BinNodeGen类中的泛型T是Comparable的子类。您可以在接口BinTreeGenterface中使用T。在
BinTreeGenterface
部分,您试图指定什么?是否要编写
BinTreeGenterface
?请您的问题包括您拥有的源代码,并描述类是如何应该实现哪些接口。Java中的泛型是一个很好的起点,我认为您需要更新一些想法。我添加了一些代码,希望问题能够被理解。@progman您在
bintreegenterface
部分试图指定什么?是否要编写
bintreegenterface
?请将您的问题包括在源代码中并描述类应该如何实现哪些接口。这是Java中泛型的一个很好的起点,我认为您需要更新一些想法。我添加了一些代码,希望能够理解这个问题。@Progman