Wrapper classes and value-based classes in Java are related but not the same. A wrapper class (e.g., Integer, Double) wraps a primitive type and has existed since the JDK's early days. A value-based class is a broader concept introduced in JDK 16 as part of Project Valhalla, implemented as an internal annotation. All wrapper classes are value-based classes, but not all value-based classes are wrapper classes — the annotation also applies to date/time API classes, Optional, and some unmodifiable collections. The annotation triggers compile-time warnings when you use these classes in ways that will break once Valhalla is fully integrated, such as using their instances for synchronization. Notably, this annotation is internal to the JDK and cannot be applied to user-defined classes.

1m watch time

Sort: