File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -425,7 +425,18 @@ public boolean equals(Object anObject) {
425425
426426![ hashCode() 方法] ( https://oss.javaguide.cn/github/javaguide/java/basis/java-hashcode-method.png )
427427
428- ` hashCode() ` 定义在 JDK 的 ` Object ` 类中,这就意味着 Java 中的任何类都包含有 ` hashCode() ` 函数。另外需要注意的是: ` Object ` 的 ` hashCode() ` 方法是本地方法,也就是用 C 语言或 C++ 实现的,该方法通常用来将对象的内存地址转换为整数之后返回。
428+ ` hashCode() ` 定义在 JDK 的 ` Object ` 类中,这就意味着 Java 中的任何类都包含有 ` hashCode() ` 函数。另外需要注意的是: ` Object ` 的 ` hashCode() ` 方法是本地方法,也就是用 C 语言或 C++ 实现的。
429+
430+ > 注:
431+ >
432+ > 该方法在 ** Oracle OpenJDK8** 中默认是 "使用线程局部状态来实现 Marsaglia's xor-shift 随机数生成", 并不是 "地址" 或者 "地址转换而来", 不同JDK/VM可能不同
433+ >
434+ > 在 ** Oracle OpenJDK8** 中有六种生成方式 (其中第五种是返回地址), 通过添加VM参数: -XX: hashCode =4 启用第五种。
435+ >
436+ > 参考源码:
437+ >
438+ > https://hg.openjdk.org/jdk8u/jdk8u/hotspot/file/87ee5ee27509/src/share/vm/runtime/globals.hpp , 1127行
439+ > https://hg.openjdk.org/jdk8u/jdk8u/hotspot/file/87ee5ee27509/src/share/vm/runtime/synchronizer.cpp , 537行开始
429440
430441``` java
431442public native int hashCode();
You can’t perform that action at this time.
0 commit comments