java - 关于HashMap源码中hash(Object key)方法原理问题
迷茫
迷茫 2017-04-18 09:27:30
0
1
560

在HashMap源码中,hash(Object key)方法的代码如下:

static final int hash(Object key) {
 int h;
 return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}

我的问题是为什么不直接使用key.hashCode()拿到哈希值,反而在后面追加 ^ (h >>> 16)处理,为什么要这么做以及能带来什么好处?谢谢!

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
PHPzhong

You can read this article, specifically about HashMap, How does a HashMap work in JAVA

About the implementation you see, it is the java8 version, it was not like this before.

Still the article above, please pay attention to the following chapters:

It should be helpful for you to understand

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template