hashcode是否返回内存地址? [英] Does hashcode return the memory address?

查看:160
本文介绍了hashcode是否返回内存地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

什么是对象哈希码

hashCode()和identityHashCode()如何在后端工作?

我不是在讨论String类或其他重写hashcode的类。假设我只是创建 Object 类的新对象,那么 hashcode()或者是真的无论如何, identityHashCode(Object x)返回该对象的内存地址?

I'm not talking about String class or any other class where the hashcode is overridden. Say if I just create a new object of the Object class, then will the hashcode() or to be true in any case, identityHashCode(Object x) return the memory address of that object?

推荐答案

不一定。来自文档 (强调我的):

Not necessarily. From the documentation (emphasis mine):


尽管相当实用,但是由Object类定义的hashCode方法确实为不同的对象返回不同的整数。 (这通常通过将对象的内部地址转换为整数来实现,但JavaTM编程语言不需要此实现技术。)

这篇关于hashcode是否返回内存地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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