很好奇java是如何通过hashCode()生成hash值的对象 API 的方法?
最佳答案
Object
的hashCode()
其实是一个native方法,实现其实不是纯Java。现在,关于它是如何工作的,this answer from Tom Hawtin很好地解释了它:
Many people will claim that
Object.hashCode
will return the address of the object representation in memory. In modern implementations objects actually move within memory. Instead an area of the object header is used to store the value, which may be lazily derived from the memory address at the time that the value is first requested.
整个答案实际上值得一读。
关于java - java的hashCode()方法是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1959948/