Kotlin 2.5.0 adds full value classes in Alpha
Brief
Kotlin 2.5.0 makes full value classes available in Alpha, with support across Kotlin platforms and an optional path to JVM value classes on JDK 28 or later.
What changes
- Full value classes are immutable and can have any number of primary properties, but cannot have backing fields outside those properties.
- They generate equals(), hashCode(), and toString(), but not copy() or componentN(); destructuring matches properties by name.
Availability and caveats
- The feature is Alpha, not production-ready, and breaking changes are expected. Enable it with -Xfull-value-classes.
- With JDK 28 or later, -Xvalhalla-value-classes enables compilation to JVM value classes using Project Valhalla.
- Kotlin 2.5.20 is planned to add migration warnings and the common inline modifier for inline value classes. Copy-property updates are planned for Kotlin 2.6.0.
Generated by AI from the original article. Check the source for full details.