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

Florian Weimer fw at deneb.enyo.de
Thu Mar 5 08:25:58 UTC 2020


* 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.

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();

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?


More information about the valhalla-dev mailing list