-
Notifications
You must be signed in to change notification settings - Fork 46.1k
2.2.8 小节对HashMap树化的描述有一点问题 #735
Copy link
Copy link
Closed
Labels
discussdiscuss a problemdiscuss a problemdoc-bugContent errorContent errorenhancementNew feature or request or suggestionNew feature or request or suggestionperfectImprove knowledge points or descriptionsImprove knowledge points or descriptions
Metadata
Metadata
Assignees
Labels
discussdiscuss a problemdiscuss a problemdoc-bugContent errorContent errorenhancementNew feature or request or suggestionNew feature or request or suggestionperfectImprove knowledge points or descriptionsImprove knowledge points or descriptions
作者在 JDK1.8之后 这一小节的开头中写道:
这段话加粗部分的描述是不准确的,当链表长度大于阈值时,会尝试调用树化方法
treeifyBin,但这不意味着会将链表转为树:当我们查看树化方法
treeifyBin(JDK1.8 HashMap源码)时,应注意到这么一行代码(757行):我们发现,当哈希表的
length小于MIN_TREEIFY_CAPACITY(默认为64)时,并不会真正树化,而只是执行resize(),也就是扩容的操作,这一点在对树化方法treeifyBin以及MIN_TREEIFY_CAPACITY的注释中都有提到:
如果我的看法有什么错漏之处,恳请大家补充指正