[jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v4]

Jorn Vernee jvernee at openjdk.java.net
Mon Jun 28 18:32:09 UTC 2021


On Wed, 23 Jun 2021 19:21:02 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> Add java.util.Objects.newIdentity to supply a unique object with identity.
>> This is a replacement code can be used today for the traditional new Object() idiom, which will be deprecated under Project Valhalla.
>> Refer to [JEP 401: Primitive Objects (Preview)](https://openjdk.java.net/jeps/401) for background.
>
> Roger Riggs has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Updated spec of Objects.newIdentity with:
>   "The class does not override any of the methods of {@code java.lang.Object}."

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

> 46:         errors += testNonNull();
> 47:         errors += testNonNullOf();
> 48:         errors += testNewIdentity();

The javadoc of `Objects::newIdentity` claims `[the returned object] can be used for synchronization`. Would it be useful to add a test that tries to synchronize on the result of `Objects.newIdentity` for that as well?

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

PR: https://git.openjdk.java.net/jdk17/pull/112


More information about the core-libs-dev mailing list