Kotlin 2.5.0 introduces full value classes in Alpha as a way to make immutable, data-oriented programming as convenient as data classes while enforcing stronger value semantics and potentially improving performance. A full value class can contain any number of primary properties, but its entire state must come from those properties: additional properties may be computed, not stored. The compiler generates equality, hashing, and string conversion, but not data classes’ copy and component functions. Instead, value classes support name-based destructuring, and a proposed “copy properties” feature for ergonomic immutable updates is planned for an Alpha release in Kotlin 2.6.0. Migration warnings for classes marked as future value classes are planned from Kotlin 2.5.20.
The feature works across Kotlin platforms and JDK versions, while an optional compilation mode can map value classes to JVM value classes using Project Valhalla, which requires JDK 28 or later. Kotlin is also expanding existing single-property inline value classes: from 2.5.20, the inline modifier can replace @JvmInline, with consistent requirements across platforms. Because value classes have no object identity, referential equality and synchronization are inappropriate; compiler diagnostics aim to catch these and other pitfalls, including suspicious equality comparisons and potentially unsafe lambda captures. The features remain experimental, with breaking changes possible, and broader optimizations and interoperability improvements for Native, JavaScript, WebAssembly, Android, Swift, and C remain future work.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.