我是泛型新手,这是我的问题:
public class Tree<T> {
public Collection<Tree<T>> getSubTrees(){};
public Tree<T> getTree(T element){}
}
public class DataTree extends Tree<Data>{
public void someMethod(){
DataTree dataTree = this.getTree(root) ;// type mismatch
Collection<DataTree> leafs = this.getSubTrees(); //type mismatch
//following works
Tree<Data> dataTree = this.getTree(root);
Collection<Tree<Data>> leafs = this.getSubTrees();
}
}
你能告诉我为什么会出现这样的错误,或者如何正确地将 Tree<Data> 转换为 DataTree 以调用 DataTree 特定的方法吗?