On Tue, 18 Jan 2022 23:15:20 GMT, Joe Darcy <da...@openjdk.org> wrote:

> While it is strongly recommend to not use the default toString for a class, 
> at times it is the least-bad alternative. When that alternative needs to be 
> used, it would be helpful to have the implementation already available, such 
> as in Objects.toDefaultString(). This method is analagous to 
> System.identityHashCode.
> 
> Please also review the CSR: https://bugs.openjdk.java.net/browse/JDK-8280184

src/java.base/share/classes/java/util/Objects.java line 170:

> 168:      * {@return a string equivalent to the string returned by {@code
> 169:      * Object.toString} if that method is not overridden}
> 170:      *

The original Object.toString() invokes the hashCode() method.
Perhaps the spec should indicate that it calls IdentityhashCode() instead of 
hashCode().

Though not incorrect, in Valhalla, Not all objects have identity and will need 
to different implementation.

Are there any use cases in the JDK that will use this method?

-------------

PR: https://git.openjdk.java.net/jdk/pull/7139

Reply via email to