On Tue, 29 Jun 2021 05:47:03 GMT, Tagir F. Valeev <tval...@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.

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

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

Reply via email to