How do you construct an instance of it?
You don't. The Java API documentation says "The
Void
class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void."
But as you said, it's not void
, so Kotlin's type-sytem is indeed smoother in this respect.
Kotlin's
Unit
is not
void
either.
Unit
is an object. From Java's point of view,
Unit
is a class which has only one instance,
Unit.INSTANCE
. This is analogous to
Void
, which is a class that has no instances, so any Java method that returns a
Void
type can only return
null
, just as any Kotlin function that returns a
Unit
type can only return the instance
Unit
.