Trying to understand the basics of Kotlin Multipla...
# multiplatform
k
Trying to understand the basics of Kotlin Multiplatform here. One question I have is why value classes can be used as the
actual
to meet an
expect
declaration - for example:
Copy code
expect class MyClass(value: Int) // common

@JvmInline
actual value class MyClass actual constructor(val value: Int) // jvm
Any high-level insight as to why that would be is appreciated.
l
Not sure what kind of answer you're looking for?
k
I get a compiler error saying that the second statement is not compatible with the first, saying that
value
makes it incompatible.
l
Use
expect value class ...
k
What if the class on other platforms is not a value class?
l
The semantics between value classes and regular classes is different.
Just define it like so:
expect value class Foo(val instance: Any)
and then the value class can just be a wrapper around the real one.
I actually did exactly that in my multiplatform bigint library.
k
So it's not possible to have an expect where the actual is a value class on one platform and not a value class on another?
l
That should not be possible, no.