因此,當試圖將我的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