【发布时间】:2015-12-17 08:06:52
【问题描述】:
假设 System.identityHashCode(object1)==123 和 object1 已被垃圾回收。新创建的object2 是否有可能与object1 在被GC 之前拥有相同的身份哈希码?
【问题讨论】:
-
是的,完全有可能。
-
甚至有可能同时存在的两个对象拥有相同的
identityHashCode。 -
请注意
System.identityHashCode()的行为与Object.hashCode()的行为相同——它只是忽略了子类中的任何hashCode()覆盖