RFR [lworld] 8239929: Object.newIdentity() replacement for new Object()

Roger Riggs Roger.Riggs at oracle.com
Thu Mar 5 18:22:36 UTC 2020


Hi Florian,

On 3/5/20 3:25 AM, Florian Weimer wrote:
> * Roger Riggs:
>
>> To keep it simple and localized, the factory method is in the
>> IdentityObject interface.
> With this, this does not compile:
>
> public class T {
>      public static void main(String[] args) {
>          newIdentity();
>      }
> }
>
> However, at run time, I assume that all instances of T implement the
> IdentityObject interface.  I find this somewhat jarring.
There are quite a few rough edges yet...

My own thinking is that nudging toward being explicit about identity is 
a good thing.
But I expect the language model folks to be more definitive about the 
tradeoffs.

In the use case above, it seems kind of a convenient accident to make 
newIdentity() implicitly
visible as a method of T. There doesn't seem to be any relationship 
between T and
the use of newIdentity().

>
> Why don't we expose the class?  For example, HashSet has this:
>
>      // Dummy value to associate with an Object in the backing Map
>      private static final Object PRESENT = new Object();
In the new model, not every "Object" carries identity so its important 
to be explicit.

There's preference for static factories instead of constructors;
it provides more flexibility in the way it is implemented.
>
> Wouldn't be nice to be able to write this instead?
>
>      private static final Marker PRESENT = new Marker();
>
> To make it explicit that this is an instance of a special class?
>
> And maybe add another class for the other common usage, a lock?
Application specific types for semantically significant instances is a plus.
Is very easy today to create new types for applications , but they 
typically don't take the trouble.
Using 'Object' for all of them is convenient but is kind of sloppy but 
very convenient.

Regards, Roger



More information about the valhalla-dev mailing list