[jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v5]
Remi Forax
forax at univ-mlv.fr
Tue Jun 29 17:31:14 UTC 2021
----- Original Message -----
> From: "Roger Riggs" <rriggs at openjdk.java.net>
> To: "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Sent: Mardi 29 Juin 2021 18:44:04
> Subject: Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v5]
> On Tue, 29 Jun 2021 05:47:03 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:
>
>>> Roger Riggs has updated the pull request incrementally with one additional
>>> commit since the last revision:
>>>
>>> Add test synchronizing on return value of Objecst.newIdentity()
>>
>> Probably it would be better to have an inner class named like `Identity` instead
>> of anonymous class? When debugging or analyzing memory dumps, it would be more
>> user-friendly to see `Objects$Identity` than `Objects$1`.
>>
>> Probably, not the part of this feature request, but it would be nice to add
>> another method with string parameter, like `Objects.newIdentity("MY
>> SENTINEL")`. The string should be stored in the field and returned from
>> toString(). Again, this would make it easier to find where the object comes
>> from during debugging or memory dump analysis. For the record, here's what we
>> have in IntelliJ IDEA sources (Apache 2.0 licensed):
>>
>>
>> public final class ObjectUtils {
>> private ObjectUtils() { }
>>
>> ...
>>
>> /**
>> * Creates a new object which could be used as sentinel value (special value to
>> distinguish from any other object). It does not equal
>> * to any other object. Usually should be assigned to the static final field.
>> *
>> * @param name an object name, returned from {@link #toString()} to simplify the
>> debugging or heap dump analysis
>> * (guaranteed to be stored as sentinel object field). If sentinel is
>> assigned to the static final field,
>> * it's recommended to supply that field name (possibly qualified
>> with the class name).
>> * @return a new sentinel object
>> */
>> public static @NotNull Object sentinel(@NotNull @NonNls String name) {
>> return new Sentinel(name);
>> }
>>
>> private static final class Sentinel {
>> private final String myName;
>>
>> Sentinel(@NotNull String name) {
>> myName = name;
>> }
>>
>> @Override
>> public String toString() {
>> return myName;
>> }
>> }
>
> @amaembo Good suggestion for the Valhalla API and implementation. Today, only
> the hashCode() identifies an Object.
> For JDK17, it will continue to be a raw Object() instance.
We should try to have a very limited API surface for now.
We want to let the door open to having Object being both an identity class (when used with "new") and an abstract class (when inherited) by using two different generic specialization of the same class or whatever other scheme we come before Valhalla is complete.
>
> -------------
>
> PR: https://git.openjdk.java.net/jdk17/pull/112
Rémi
More information about the core-libs-dev
mailing list