min
08/20/2026, 7:20 AM@JvmInline value class MyInt(val n: Int)
Why do I need the @JvmInline annotation?min
08/20/2026, 7:22 AMCLOVIS
08/20/2026, 7:37 AMWhy do I need theValue classes were added to Kotlin before they were added to Java. Because we want Kotlin to be compatible with Java, it was decided to future-proof by having two variants of value classes: Withannotation?@JvmInline
@JvmInline , it creates a value class handled by the Kotlin compiler, not compatible with Java. Added in Kotlin 1.3.
@JvmInline
value class MyInt(val n: Int)
Without @JvmInline , it will create a value class handled by the JVM, compatible with Java.
value class MyInt(val n: Int)
This kind of value class is not yet available because Java's value objects are not released yet (targeted for Java 28 as far as I can see).CLOVIS
08/20/2026, 7:41 AMhow are Kotlin `value class`es and Java value objects different?With
@JvmInline , the compiler removes the class wherever it can (TL;DR everywhere except generics and supertypes). More info in the documentation: kotlinlang.org/docs/inline-classes.html
Without @JvmInline , it will be compiled to a Java value object. Since value objects are not released yet, this is not yet implemented and is currently being discussed. You can see the (tentative) specification here:
• github.com/Kotlin/KEEP/blob/…/KEEP-0453-better-immutability-value-classes…
• github.com/Kotlin/KEEP/blob/…/KEEP-0454-better-immutability-value-classes…min
08/20/2026, 7:44 AM@JvmInline, the type is ‘not compatible’ with Java.
• Without @JvmInline, it’ll match whatever Java ends up shipping.
Right? What does it mean for a @JvmInline value class to be ‘not compatible’ with Java though? It’s invisible to Java code? Or it’s costly?CLOVIS
08/20/2026, 7:59 AMRight?Yes.
It’s invisible to Java code?Java can see a class `MyInt`but cannot call its constructor. Java cannot call methods that take a
MyInt as parameter.
For example a method
fun foo(a: MyInt) {
println("hello world ${a.a}")
}
is compiled on the JVM to
public final class InlineKt {
public static final void foo_cflvL_8(int a) {
System.out.println("hello world " + a);
}
}
The function foo_cf1vL_8 is "special", the Java compiler will not let you call it even if you try.CLOVIS
08/20/2026, 8:00 AM@JvmName , see kotlinlang.org/docs/inline-classes.html#…CLOVIS
08/20/2026, 8:02 AM@JvmInline
@JvmExposeBoxed
value class MyInt(val a: Int)
which is exactly the same as @JvmInline value class for Kotlin users but is visible as a regular class for Java/Scala/etc users. See github.com/Kotlin/KEEP/blob/…/jvm-expose-boxed.md
This will probably only really be useful for users of @JvmInline value class in libraries that want their code to be available to Java but without making breaking changes.Marat Akhin
08/20/2026, 8:16 AMtargeted for Java 28 as far as I can seeAs the first preview release, yes. When they will become stable, we have no idea atm. Very optimistic plans are JDK 29 (the next LTS), we'll see whether this happens or not.
Marat Akhin
08/20/2026, 8:17 AMCLOVIS
08/20/2026, 8:17 AMVery optimistic plans are JDK 29 (the next LTS)Is there any chance that happens? 😅 That seems like a very short timeframe
CLOVIS
08/20/2026, 8:18 AMMarat Akhin
08/20/2026, 8:23 AMCLOVIS
08/20/2026, 8:25 AMMarat Akhin
08/20/2026, 8:29 AMCLOVIS
08/20/2026, 8:43 AMMarat Akhin
08/20/2026, 8:44 AMmin
08/20/2026, 10:21 AMCLOVIS
08/20/2026, 12:10 PM@JvmInline was added in 1.3 (2018!), we all knew value classes would take years to be properly added to the JVM and it was worth it having a limited variant early. I'm not sure anyone thought it'd be a 10 years gap though 😅Marat Akhin
08/20/2026, 12:17 PMCLOVIS
08/20/2026, 12:59 PMcopy var ?? 👀Marat Akhin
08/20/2026, 1:01 PM