Java Object.hashCode()-地址还是random()? [英] Java Object.hashCode() - address or random()?

查看:51
本文介绍了Java Object.hashCode()-地址还是random()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解hashCode()方法的本机实现.该方法究竟返回什么?是内存地址还是随机值?

I'm trying to understand the native implementation of the hashCode() method. What exactly does this method return? Is it a memory address or is it a random value?

推荐答案

.hashCode()本机实现取决于JVM.

.hashCode() native implementation depends on JVM.

例如HotSpot具有6个Object.hashCode()实现.您可以使用-XX:hashCode=n标志通过命令行运行JVM来选择它,其中n:

E.g. HotSpot has 6 Object.hashCode() implementations. You can choose it using -XX:hashCode=n flag running JVM via command line, where n:

0 – Park-Miller RNG(默认)
1 – f(地址,global_statement)
2 –常数1
3 –串行计数器
4 –对象地址
5 –线程本地Xorshift

0 – Park-Miller RNG (default)
1 – f(address, global_statement)
2 – constant 1
3 – Serial counter
4 – Object address
5 – Thread-local Xorshift

这篇关于Java Object.hashCode()-地址还是random()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆