且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

`hashCode`的默认实现是什么?

更新时间:2022-03-24 22:33:03

然后这个类从其祖先之一继承 hashCode 。如果没有覆盖它,那么使用了Object.hashCode

Then this class inherits hashCode from one of its ancestors. If non of them overrides it, then Object.hashCode is used.

来自 docs


As在合理实际的情况下,由Object类定义的hashCode方法确实为不同的对象返回不同的整数。 (这通常通过将对象的内部地址转换为整数来实现,但JavaTM编程语言不需要此实现技术。)

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

因此默认实现是特定于JVM的

So default implementation is JVM-specific