ConcurrentHashMap jdk 8 Uses TreeNodes instead of List .. Why? [closed]

五迷三道 提交于 2019-11-29 05:20:56

The main changes are to add ConcurrentHashMap specific implementations of the new Java 8 default Map methods with better concurrent implementations that rely on the internal details. These changes required lots of new inner classes which bloat the .java file

For example, some of these methods include:

compute(K key, BiFunction remappingFunction)

forEach(BiConsumer action)

merge(K key, V value, BiFunction remappingFunction)

Just to name a few.

I think this also shows why you usually shouldn't care about implementation details on how a class you don't have to maintain works. As long as the class follows the contract laid out in its javadoc, you should be agnostic of how it works since the implementation details can change in the future.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!