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

Add Objects.toIdentityString

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 19
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Add a new static method to a system class.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Add Objects.toIdentityString.

      Problem

      At times, a toString mapping independent of the class-provided mapping needs to be used and such a method is not present in the platform.

      Solution

      Add a method with the functionality in question to java.util.Objects.

      Specification

      +    /**
      +     * {@return a string equivalent to the string returned by {@code
      +     * Object.toString} if that method and {@code hashCode} are not
      +     * overridden}
      +     *
      +     * @implSpec
      +     * The method returns a string equivalent to:<br>
      +     * {@code o.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(o))}
      +     *
      +     * @param o an object
      +     * @throws NullPointerException if the argument is null
      +     * @see Object#toString
      +     * @see System#identityHashCode(Object)
      +     * @since 19
      +     */
      +    public static String toIdentityString(Object o) {
      +        requireNonNull(o);
      +        return o.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(o));
      +    }
      +

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              darcy Joe Darcy
              Reporter:
              darcy Joe Darcy
              Reviewed By:
              Alan Bateman, Mandy Chung, Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: