Making Object abstract
brian.goetz at oracle.com
Wed Jun 2 14:57:52 UTC 2021
A minor bikeshed comment: We're asking users to change their `new
Object()` to `IdentityObject.newIdentity()`, and they may ask "why do I
have to say 'Identity' twice"? (And by ask, I mean grumble, because
we're already asking them to change their working code.)
After a few minutes of thought, I think it might be a better fit to put
this at Objects::newIdentity. The methods in Objects are conveniences
that users could write themselves, which this basically is -- there's
nothing special about this method, other than having a preferred
alternative to `new Object()` which users will understand. So parking
this where the Object conveniences go seems slightly lower friction.
On 6/2/2021 10:50 AM, Dan Smith wrote:
>> On May 8, 2021, at 1:20 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>> I agree that we can introduce the new API point immediately. The 17 window hasn't even closed yet! But we'd have to get a move on. But realistically, we can expect it to be several years before we are comfortable erroring on the `new Object()` constructor.
> Update: we spent a little time discussing "what does this API look like?", and settled on:
> - A new static factory method, java.lang.IdentityObject.newIdentity()
> - A possibly-private implementation class, java.lang.Identity or jdk.internal.Identity
> - javac treats 'new Object()' as equivalent to 'IdentityObject.newIdentity()', with a warning
> - the JVM executes 'new java/lang/Object' by creating an instance of 'java/lang/Identity'
> The advantage of putting the factory in an interface is that static interface methods aren't inherited. (If we were to put it in Object, it would pollute the method namespace of all classes.)
> Of course these details can evolve, but as it stands, there's not a good path to introducing the API before we introduce primitive objects—IdentityObject has no reason to exist without primitive objects. So efforts to get people to migrate to something new will need to wait until then. (As discussed earlier in the thread, that's fine—we're inevitably going to have a period of time when 'new Object()' does something weird.)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the valhalla-spec-experts