RFR: JDK-8280168: Add Objects.toIdentityString [v6]

Mandy Chung mchung at openjdk.java.net
Mon Jan 24 22:04:07 UTC 2022


On Mon, 24 Jan 2022 21:27:06 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java line 295:
>> 
>>> 293:         assert(isObjectMethod(m)) : m;
>>> 294:         return switch (m.getName()) {
>>> 295:             case "toString" -> java.util.Objects.toDefaultString(self);
>> 
>> It might be better if toString is changed to invoke toIdentityString(self), only because hashCode returns the identity hash code, it doesn't invoke hashCode().
>
> Yes; that looks like an inconsistency/bug. Updated in a subsequent push.

Yes, it's a bug and it should call the one with identity hash code.   The `toString` method of a Proxy instance should return the result of the default implementation of `Object::toString` method as specified.

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

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


More information about the core-libs-dev mailing list