Reputation: 838
I try to implement an interface and in the generic of the interface I extend from Comparable. For some reason this causes the error message to appear, but I don't know why.
public class BinTreeGen<T> implements BinTreeGenInterface<E extends Comparable<E>>{}
This are the two errors: multiple markers at this line - Syntax error on token ">>", { expected after this token - Syntax error on token "extends", , expected
The code from the Interface:
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();
}
and this code I try to implement in my BinTreeGen class:
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;
}
}
(I know its full with bugs)
Upvotes: 0
Views: 120
Reputation: 21
First the header of your class BinTreeGen is wrong, therefor you get the error "Bound mismatch"!!! Your class header is:
public class BinTreeGen<T> implements BinTreeGenInterface<E extends Comparable<E>> { ....}
You should change it to:
public class BinNodeGen<T extends Comparable<T>> implements BinTreeGenInterface<T> { ....}
The generic typ T in class BinNodeGen is a subclass of Comparable you can use the T in your Interface BinTreeGenInterface
Upvotes: 2