in the future?
This to me seems like a prime use case of inline classes, as type aliases are not an option if there are tiny differences between the expected and actual type.
I previously assumed that this is already possible, but it isn't, and I don't see a reason why it shouldn't be other than a bit of implementation complexity.
👍🏼 1
r
russhwolf
02/19/2019, 5:20 PM
I've never tried it but can you do
expect inline class
?
d
Dico
02/19/2019, 5:26 PM
Yes, but the
expect
declaration requires a primary constructor with a property parameter.
Copy code
expect inline class Hello(val string: String)
actual inline class Hello(val del: Any) {
actual constructor(string: String) : this(string as Any)
actual val string: String get() = del.toString()
}
fun main() {
val hello = Hello("5000")
println(hello.string)
}
Dico
02/19/2019, 5:27 PM
This does compile and run though, despite the requirement to have the constructor with a property. Strangely.