I'm using the Idiom from this Discussion How can I make an interface instance method accept arguments of the same class only, really?:
interface ITree<SELF extends ITree<SELF>>{
SELF getNode(int index);
void setNode(int index, SELF node);
}
My question is, how can I implement the Tree which extends ITree in a right why? My current code looks like this:
public class B {
private ITree tree;
public B (ITree tree){
this.tree = tree;
}
}
As expected it throws warnings that I should add a Type. I want to let the class which uses B decide which Type it should use. Or better I don't want to use generics at all for such a minor Problem.
Edit:
I found the solution after evaluating the answers. The devils detail was in this line:
<T extends ITree<T>>
Here is the full source code:
public class B<T extends ITree<T>> {
private T tree;
public B (T tree){
this.tree = tree;
}
}