如果不重写hashCode
方法,hashCode
的默认实现是什么?
最佳答案
然后这个类从它的一个祖先继承hashCode
。如果没有一个覆盖它,那么 Object.hashCode被使用了。
来自 docs :
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 的
关于java - `hashCode` 的默认实现是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15130764/