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.)
/**
* 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.)
- csr for
-
JDK-8269097 Add java.util.Objects.newIdentity method
- Closed
- is cloned by
-
JDK-8269172 Add java.util.Objects.newIdentity method
- Resolved
- relates to
-
JDK-8317279 Standard library implementation of value classes and objects
- In Progress
-
JDK-8237073 [lworld] Need special handling of jlO constructor invocation
- Resolved
- links to
-
Review openjdk/jdk17/112