[英]why in Java8 the TreeNode subclass in HashMap extends LinkedHashMap.Entry instead of directly extending HashMap's Node subclass?
Actually a treenode is a node of a red-black tree, and needs a parent field, a left field and a right field to form a tree.实际上,treenode 是红黑树的一个节点,需要一个父域、一个左域和一个右域来组成一棵树。 but I don't see any necessity for it to have some attributes of an LinkedHashMap.Entry.但我认为它没有任何必要具有 LinkedHashMap.Entry 的某些属性。
Is there anyone who knows the reason?有谁知道原因吗?
Maybe because the gain from having separate TreeNode
in HashMap
and LinkedTreeNode
in LinkedHashMap
is marginal?也许是因为在HashMap
中拥有单独的TreeNode
和在LinkedHashMap
中拥有LinkedTreeNode
的收益是微不足道的?
Or because LinkedHashMap
needs a LinkedTreeNode
that would need to extend from to separate classes?还是因为LinkedHashMap
需要一个LinkedTreeNode
需要从扩展到单独的类?
Let's assume that HashMap
had a HashMap.TreeNode
class that extends solely from HashMap.Node
.让我们假设HashMap
有一个HashMap.TreeNode
class 仅从HashMap.Node
扩展而来。
LinkedHashMap
needs a similar class LinkedHashMap.LinkedTreeNode
that needs to extend from LinkedHashMap.Entry
(which in turn extends from HashMap.Node
), but would also need to extend from HashMap.TreeNode
because of the way the two classes are interwoven. LinkedHashMap
needs a similar class LinkedHashMap.LinkedTreeNode
that needs to extend from LinkedHashMap.Entry
(which in turn extends from HashMap.Node
), but would also need to extend from HashMap.TreeNode
because of the way the two classes are interwoven.
That would require extending from two classes, which Java explicitly prohibits.这需要从两个类扩展,Java 明确禁止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.