RFR: JDK-8280168 Add Objects.toDefaultString [v5]
Joe Darcy
darcy at openjdk.java.net
Thu Jan 20 23:27:48 UTC 2022
On Thu, 20 Jan 2022 23:20:37 GMT, Joe Darcy <darcy at 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
>
> Joe Darcy has updated the pull request incrementally with one additional commit since the last revision:
>
> Appease jcheck.
Expanding the scope of the proposed change, perhaps outside of a good cost/benefit ratio, there are now two new methods:
toDefaultString(Object o) // uses o.hashCode
toIdentityString(Object o) // uses System.identityHashCode(o)
The revision refactors two occurrences of the logic of toDefaultString with calls to the new method.
The toIdentityString method has the sometimes helpful property that no overridden methods of the object are called in constructing the string.
I'll revise the CSR once the final set of methods and their spec for this fix is determined.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7139
More information about the core-libs-dev
mailing list