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));
+ }
+
- csr of
-
JDK-8280168 Add Objects.toIdentityString
-
- Resolved
-