why is this not compiling (complains about lateini...
# getting-started
g
why is this not compiling (complains about lateinit)?
Copy code
class SpySleeper: Sleeper {
    lateinit var sleepDuration: Duration

    override fun sleep(d: Duration) {
        sleepDuration = d
    }
}

interface Sleeper  {
    fun sleep(duration: Duration)
}
s
What error do you see? This compiles fine for me.
g
‘lateinit’ modifier is not allowed on properties of inline class types
s
Ah, okay. I missed the fact that
Duration
is
kotlin.time.Duration
.
g
neither can i add
?
after
Duration
to make it nullable
well, this
var sleepDuration: Duration = Duration.ZERO
seem to have worked
s
how about the old-style notNull-Delegate? It might work with inline classes!?
Copy code
var sleepDuration: Duration by Delegates.notNull()
that's basically what you'd have used before there was
lateinit
. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.properties/-delegates/not-null.html
👍 1