Value-based Classes

Some classes, such as java.lang.Integer and java.time.LocalDate, are value-based. In a future release, they may become value classes (JLS §8.1.1.5PREVIEW).

A value-based class has the following properties:

When two instances of a value-based class are equal (according to `equals`), a program should not attempt to distinguish between their identities, whether directly via reference equality == or indirectly via an appeal to synchronization, identity hashing, serialization, or any other identity-sensitive mechanism.

Synchronization on instances of value-based classes is strongly discouraged, because the programmer cannot guarantee exclusive ownership of the associated monitor.

When preview features are enabled, some value-based classes become value classes. Instances of these classes become value objects, which have different identity-related behaviors compared to identity objects: