Experimental inline classes

Is there any idea on when inline classes will be made non-experimental?

1 Like

Hopefully sometime between 1.4 and 1.5, but they still have a lot of issues with them as they stand.

For example, I submitted an issue where the compiler has problems compiling a call to an inline class’s function that implements an interface’s function that uses default parameters and actually makes use of the default parameters

interface HasValue {
    val value: Int

    fun defaultParameter(withParameter: Int = 1) {
        println("defaultParameter call with $withParameter")
    }
    fun noDefaultParameter(withParameter: Int) {
        println("noDefaultParameter call with $withParameter")
    }
}

inline class InlinedCertainValue(override val value: Int): HasValue

fun main() {
    val a = InlinedCertainValue(100)
    a.defaultParameter() // Comment this line out and you will not get a code generation exception
    a.noDefaultParameter(25)
    a.defaultParameter(66)
}
```.

Thx! Hope they will manage to fix the issues soon.

https://youtrack.jetbrains.com/issue/KT-23338
This issue still contain 84 unresolved subtasks, so I guess there is still some work to be done. Another holdup is probably the missing design for inline enums and maybe a better design for the java interop, which isn’t that great right now. Therefor I don’t think inline classes will be marked as stable before the 1.5 release. My guess is that this will be part of a mayor version so either 1.5 or 1.6.

That said unless you run into one of the obscure compiler crashes related to inline classes they work fine. I use them in my projects without any issues. And if you run into one of the codegen exceptions you can always revert the inline class to a normal class without many problems.
Just add a hashCode and equals function and everything works the same, just with boxing. Of cause this is not an option for libraries that need to keep a consistent API/ABI, but for applications using inline classes right now should be no problem.

1 Like