我试图实现一个基本的二进制搜索树(与问题无关).这就是我所拥有的:
public class BSTNode {
public T data;
public BSTNode left;
public BSTNode right;
}
public class BinarySearchTree {
private BSTNode root;
public BSTNode insert(T item){
BSTNode newNode = new BSTNode();
newNode.data = item;
if(root == null){
root = newNode;
}
return newNode;
}
}
插入方法不完整.但是,我在’root = newNode;’上收到以下编译错误if块中的行:
Type mismatch: cannot convert from BSTNode to BSTNode
我无法绕过这个.它们是相同的通用类型.为什么编译器会抱怨?
我在Eclipse Mars中使用JDK 8.