——这是我第一次在csdn上写blog。在我学习了自动装箱和拆箱相关内容之后,我对JVM的运行机制有所好奇,于是想进一步探索Java的内存分配原理。本文给出object.hashCode() 与 System.identityHashCode() 的比较,算是我的见解和在别处学到的东西。在其他文章中,我还形象分析了Integer、String对象在内存中的创建过程。欢迎大家浏览和更正。
概念与比较
标识哈希码(identity hash code)
是java.lang.Object.hashCode()或者java.lang.System.identityHashCode(obj)的返回值,它是一个对象的身份标识(identity label)。在使用时,我们更多使用后者。
?这里给出API文档中的观点:
(1)object.hashCode():
(2)System.identityHashCode(obj):
从上面的概念可以看出identityHashCode是根据Object类hashCode()方法来计算hash值,