0

为什么 DefaultMutableTreeNode 中有 isRoot() 函数?我问是因为我有一个扩展 DefaultMutableTreeNode 的类。我希望能够在多个不同的 JTree 对象中使用此类的单个实例。但是,似乎 isRoot() 是我应该问树对象本身的问题。任何人都可以提供任何关于为什么这个函数存在于节点级别而不是树级别的见解吗?

4

1 回答 1

0

The tree object can't be the root of the tree; the JTree object isn't a node.

DefaultMutableTreeNode is designed to facilitate recursive traversal of the tree. Since a recursive method processing the tree will only have access to one node (and its subsequent nodes) at a time, the only way for the method to distinguish the root of the tree is for the nodes to inidivdually keep track of whether or not they are the root of the tree.

于 2014-07-24T18:37:03.207 回答