RFR: JDK-8280168 Add Objects.toDefaultString [v2]

Alan Bateman alanb at openjdk.java.net
Wed Jan 19 09:23:31 UTC 2022


On Wed, 19 Jan 2022 02:57:10 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:
> 
>   Respond to review feedback.

Marked as reviewed by alanb (Reviewer).

test/jdk/java/util/Objects/BasicObjectsTest.java line 148:

> 146:         Object o = new Object(){};
> 147:         errors += (Objects.toDefaultString(o).equals(o.toString()))? 0 : 1;
> 148:         return errors;

Another potential test is on an instance of a class that overrides toString(), that would ensure that toDefaultString() doesn't invoke toString.

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

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


More information about the core-libs-dev mailing list