EG meeting, 2020-09-09
Dan Smith
daniel.smith at oracle.com
Wed Sep 9 20:04:10 UTC 2020
> On Sep 9, 2020, at 12:15 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>
>> Remi points out that the System class (or, say, Objects) is a place we could put a factory method if we want one but don't want to risk adding it to Object.
>
> Looking at it from the other direction, I am not sure having a nominal SimpleIdentityObject class adds much value. You can of course write a do-nothing identity class yourself:
>
> class WednesdayIdentityClass extends Object { }
>
> Will anyone want to extend SIO? There's no point, since any concrete class that extends Object already becomes an IdentityObject, so they'll just extend Object.
>
> Will anyone want to use it as a parameter type / type bound? I doubt it; they'll use IdentityObject.
>
> Will anyone want to use it as a return type? I don't see much point, because there's nothing a SIO can do that Object can't. The only reason we're exposing it is as a replacement for `new Object()`, which we've deemed to be an idiom only for getting a unique identity. If we did nothing, people could replace:
>
> Object lock = new Object();
>
> with
>
> Object lock = new Object() { };
>
> (and someone would brand it the "identity brace trick".) But that's a little too obscure, so recommending
>
> Object lock = Objects.newIdentity();
>
> says exactly what you mean. The precise typestate of the result is an implementation detail; the key is that a new identity is dispensed.
Yes, this is all good from the language perspective. The outstanding bit is "what does the instruction 'new java/lang/Object' do?" The simple thing is for JVMS to say "an instance of java/lang/SimpleIdentityObject is created on the heap".
If the class is private, the JVM implementation still knows what it is, so that's probably okay, but what does JVMS say? I don't want to phrase it in a way that, say, lets a JVM implementation interpret 'new java/lang/Object' as 'new java/lang/String' or something stupid like that.
More information about the valhalla-spec-observers
mailing list