因此,当试图将我的Node<T>
投射到我的AVLNode<T>
时,我得到了这个ClassCastException
。不知道为什么。演员异常?
这里是引发异常的地方。
Node<Integer> n1 = new Node<Integer>(3, null);
AVLNode<Integer> n2 = (AVLNode<Integer>) n1;
类怎么看?
public class Node<T extends Comparable<T>> {
public Node<T> right;
public Node<T> left;
public Node<T> parent;
public T data;
public Node(T data, Node<T> parent) {
this.data = data;
this.parent = parent;
} // ...
而且在不同的文件中的其他类:
public class AVLNode<T extends Comparable<T>> extends Node<T> {
public int height = 1;
public AVLNode(T data, Node<T> parent) {
super(data, parent);
} //...
错误消息: 异常线程 “main” 的java.lang。 ClassCastException:custom.trees.Node无法转换为custom.trees.AVLNode
什么是来自异常的**精确**堆栈跟踪?为了将来的参考,**总是**发布**完整** stacktrace如果你要求帮助一个例外。 – 2014-10-31 13:50:10
线程“main”中的异常java.lang.ClassCastException:custom.trees.Node无法转换为custom.trees.AVLNode – Whizzil 2014-10-31 13:54:45
请**更新您的问题**并提供相关信息。不要把它放在评论中。 – 2014-10-31 13:55:35