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

Add Objects.toIdentityString

    XMLWordPrintable

Details

    • CSR
    • Status: Closed
    • P4
    • Resolution: Approved
    • 19
    • core-libs
    • None
    • minimal
    • Add a new static method to a system class.
    • Java API
    • 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

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

              Dates

                Created:
                Updated:
                Resolved: