Making Object abstract
daniel.smith at oracle.com
Wed Jun 2 14:50:21 UTC 2021
> 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.)
More information about the valhalla-spec-experts