`Unit` is not like `void` at all, it's just an ord...
# announcements
k
Unit
is not like
void
at all, it's just an ordinary singleton object.
y
the point is that Unit is more "special" than Nothing. Nothing can always be translated to java.lang.Void. Unit is sometimes translated to void.
this doesnt explain why Array<Nothing?> is disallowed. It is just as inhabited as Array<Unit>.
k
Unit
is not translated to
void
. As I said,
Array<Unit>
makes perfect sense, eg.
arrayOf(Unit, Unit)
is an array that contains two normal object instances.
y
Unit is translated to void for return values. Array<Nothing?> makes just as much sense as Array<Unit>, yet it is illegal.
k
Unit
is not translated to
void
for return values, if you call a
Unit
-returning function you actually get the
Unit
instance back
. You can see this if you override a Kotlin funtion in Java, you manually have to
return Unit.INSTANCE
at the end.
y
it is only the case for generics