adams2
09/18/2017, 10:52 PMorangy
doAnswer2
defines answer
as returning T?
which is nullable of T. You specify Unit
as type parameter, so your lambda should return Unit?
, nullable Unit. Which can be either null
or Unit
(singleton instance). Kotlin can automatically provide Unit
when needed, and optimize it to void on JVM, but when it’s Unit?
it can’t.