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
Sam
12/20/2022, 1:34 PM
What error do you see? This compiles fine for me.
g
Gasan
12/20/2022, 1:35 PM
‘lateinit’ modifier is not allowed on properties of inline class types
s
Sam
12/20/2022, 1:37 PM
Ah, okay. I missed the fact that
Duration
is
kotlin.time.Duration
.
g
Gasan
12/20/2022, 1:38 PM
neither can i add
?
after
Duration
to make it nullable
Gasan
12/20/2022, 1:43 PM
well, this
var sleepDuration: Duration = Duration.ZERO
seem to have worked
s
Stephan Schröder
12/20/2022, 11:24 PM
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