https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
p

PHondogo

01/26/2023, 7:14 AM
What is the best way to work with value classes in MPP? If I create them in common scope jvm side complains about lack of annotation @JvmInline, but if I add this annotation then js side complains about unresolved reference of @JvmInline.
e

ephemient

01/26/2023, 7:23 AM
use
@JvmInline
in Java and common sourcesets, don't use it in JS and native sourcesets
p

PHondogo

01/26/2023, 7:25 AM
But value class is defined in common sourceset. How can i strip this annotation for particular platform?
v

Vidmantas Kerbelis

01/26/2023, 7:44 AM
commonMain:
Copy code
expect interface NameYourAnnotation
jvmMain:
Copy code
actual typealias NameYourAnnotation = JvmInline
jsMain:
Copy code
actual interface NameYourAnnotation
- This should resolve it
e

eygraber

01/26/2023, 2:35 PM
If you use
@JvmInline
in common, js gives you an error? I'm pretty sure I've seen that work.
e

ephemient

01/26/2023, 5:21 PM
Yes. JvmInline is an
@OptionalExpectation
in common, meaning that it is fine that it only
actual
on some platforms
5 Views