What is an “internal address” in Java?

后端 未结 4 2046
你的背包
你的背包 2020-11-27 15:50

In the Javadoc for Object.hashCode() it states

As much as is reasonably practical, the hashCode method defined by class Object does retur

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 16:26

    The Javadoc's suggestion for Object.hashCode() that it is implemented by deriving the hashcode from the memory address is simply outdated.

    Probably nobody bothered (or noticed) that this implementation path is no longer possible whith a copying garbage collector (Since it would change the hashcode when the Object is copied to another memory location).

    It made a lot of sense to implement hashcode that way before there was a copying garbage collector, because it would save heap space. A non-copying GC (CMS) may still implement hashcode that way today.

提交回复
热议问题