https://kotlinlang.org logo
#announcements
Title
# announcements
a

adams2

09/18/2017, 10:52 PM
when would you return null for Unit?
o

orangy

09/18/2017, 11:10 PM
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.
1
2 Views