Dico

    Dico

    3 years ago
    Will we be able to use
    actual inline class
    to define
    expect class
    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.
    russhwolf

    russhwolf

    3 years ago
    I've never tried it but can you do
    expect inline class
    ?
    Dico

    Dico

    3 years ago
    Yes, but the
    expect
    declaration requires a primary constructor with a property parameter.
    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)
    }
    This does compile and run though, despite the requirement to have the constructor with a property. Strangely.
    It should be able to just work as a regular
    expect class
    though I think.