gpt4 book ai didi

java - 为什么 TreePath 是由 Object[] 而不是 TreeNode[] 构造的?

转载 作者:行者123 更新时间:2023-11-30 09:54:26 25 4
gpt4 key购买 nike

从 Java API 来看,JTree 的节点似乎是 TreeNode 的实例。此外,返回的所有 TreePath 似乎都是 TreeNode 的实例。那么,为什么 TreePaths 由 Object[] 表示而不是 TreeNode[]?这会在使用这些类时带来不便。

谢谢。

最佳答案

请参阅 Java tutorial 中的解释:

Interestingly, the TreeModel interface accepts any kind of object as a tree node. It does not require that nodes be represented by DefaultMutableTreeNode objects, or even that nodes implement the TreeNode interface. Thus, if the TreeNode interface is not suitable for your tree model, feel free to devise your own representation for tree nodes. For example, if you have a pre-existing hierarchical data structure, you do not need to duplicate it or force it into the TreeNode mold. You just need to implement your tree model so that it uses the information in the existing data structure.

关于java - 为什么 TreePath 是由 Object[] 而不是 TreeNode[] 构造的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3276324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com