JDK-8269096 : Add java.util.Objects.newIdentity method
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Priority: P3
  • Status: Resolved
  • Resolution: Won't Fix
  • Submitted: 2021-06-21
  • Updated: 2024-06-21
  • Resolved: 2021-07-19
Related Reports
CSR :  
Cloners :  
Relates :  
Relates :  
Sub Tasks
JDK-8269255 :  
Description
Introduce a method in the Objects utility class, something like:

/**
 * Construct a new instance of an unspecified class. The object has
 * a unique identity—no other references to it exist. It can be
 * used for synchronization, or where a placeholder Object is
 * needed. Use this method to avoid relying on the Object constructor.
 */
public static Object newIdentity() {
    return new Object() {};
}

(The method appears somewhat unmotivated for now, but with JEP 401, use of the Object constructor will be discouraged (with warnings) in Java source, and this method provides a migration path to something else.)
Comments
To be included in JEP 401.
19-07-2021

Now that we’re in RDP 2, this requires reconsideration..
15-07-2021

Late enhancement approved by Project Lead.
28-06-2021

Late Enhancement Request Add a static method `java.util.Objects.newIdentity` to supply a unique object. The risk is minimal, the proposal adds a new method to a final class with no interaction with other runtime classes. The implementation returns `new Object()` to provide a unique class. The expert group for JEP 401: Primitive Classes is requesting this addition to ease the transition when Primitive Classes are implemented.
21-06-2021