Kotlin 2.5.0-Beta2 (out since 22.10) has experimen...
# getting-started
s
Kotlin 2.5.0-Beta2 (out since 22.10) has experimental support for Full Value Classes and for generating Java 28 bytecode. Java 28 comes with preview support for value classes on the JDK. SDKMAN already offers a single early access build of JDK28: Java.net | | 28.0.0.0+ea.20 | 28.0.0.0+ea.20-open So I guess I can already play around with value classes 🤷‍♂️ But does Kotlin (2.5.0-Beta2) generate JDK28 using the new value class preview feature (it's not like the Kotlin compiler knows if I start the Java28 jdk with "-enable-preview") or something less optimal (like whatever bytecode it generates if Java 27 is configured)?
🎉 2
✅ 1
m
Thanks for the question! TL;DR: Yes, but only if you opt in. Kotlin doesn’t infer Valhalla mode just because you installed or launched a JDK 28 EA. For Kotlin 2.5.0-Beta2 you need:
Copy code
-jvm-target 28
-Xjvm-enable-preview
-Xvalhalla-value-classes
-Xfull-value-classes
-Xfull-value-classes
enables the language feature;
-Xvalhalla-value-classes
tells the JVM backend to emit Kotlin full value classes as Project Valhalla/JEP 401 value classes. Without it, Kotlin generates ordinary bytecode and value-class boxes remain identity classes.
-Xjvm-enable-preview
marks the class files as preview bytecode; at runtime you still need
--enable-preview
. So with the SDKMAN JDK 28 EA you can play with it, e.g.:
Copy code
kotlinc -jvm-target 28 \
  -Xjvm-enable-preview \
  -Xvalhalla-value-classes \
  -Xfull-value-classes \
  Main.kt -d out

java --enable-preview -cp out MainKt
Important: it is experimental/preview-only, not production-ready.
🎉 1