Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8215025

Object.hashCode should not mention anything about memory addresses

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 12
    • core-libs
    • None
    • behavioral
    • minimal
    • Specification clarification only.
    • Java API
    • SE

    Description

      Summary

      Removal of mention of memory addresses from the specification of Object.hashCode().

      Problem

      The specification of Object.hashCode() contains some odd wording about the computation possibly involving the object's memory address. This might have been the case at some point in the distant past, in an early JVM implementation, but it hasn't been true for many years. Unfortunately, this wording has caused misinformation to be repeated continually and has led to recurring confusion.

      Solution

      Remove the statement about memory addresses entirely. Reword the "distinct" sentence and recharacterize it as @implSpec.

      Specification

      diff -r 0d89f672c62e -r 6af324164325 src/java.base/share/classes/java/lang/Object.java
      --- a/src/java.base/share/classes/java/lang/Object.java Thu Dec 06 14:34:11 2018 -0800
      +++ b/src/java.base/share/classes/java/lang/Object.java Fri Dec 07 09:55:42 2018 -0800
      @@ -94,12 +94,10 @@
            *     programmer should be aware that producing distinct integer results
            *     for unequal objects may improve the performance of hash tables.
            * </ul>
      -     * <p>
      -     * As much as is reasonably practical, the hashCode method defined
      -     * by class {@code Object} does return distinct integers for
      -     * distinct objects. (The hashCode may or may not be implemented
      -     * as some function of an object's memory address at some point
      -     * in time.)
      +     *
      +     * @implSpec
      +     * As far as is reasonably practical, the {@code hashCode} method defined
      +     * by class {@code Object} returns distinct integers for distinct objects.
            *
            * @return  a hash code value for this object.
            * @see     java.lang.Object#equals(java.lang.Object)

      Attachments

        Issue Links

          Activity

            People

              smarks Stuart Marks
              smarks Stuart Marks
              Aleksey Shipilev, Andrew Dinn, Roger Riggs
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: