是否可以将 String 变量转换为 DefaultMutableTreeNode 对象?请解释。语境:
String s = new String(outputTagName);
Object s2 = (Object) s;
DefaultMutableTreeNode selectedNode2 =(DefaultMutableTreeNode) s2;
DefaultMutableTreeNode parent2 =(DefaultMutableTreeNode) parent;
model.insertNodeInto(selectedNode2, parent2, parent2.getChildCount());
这是我写的代码。这在以 BreadthFirstSearch 方式遍历树的枚举中使用。2nf 行给了我这个错误:
java.lang.ClassCastException: java.lang.String cannot be cast to javax.swing.tree.DefaultMutableTreeNode at ....