Ellen Spertus
10/25/2019, 11:38 PMVoid!?Ellen Spertus
10/25/2019, 11:39 PMPablichjenkov
10/25/2019, 11:40 PMnull is the only thing that comes to my mind.Ellen Spertus
10/25/2019, 11:41 PM!.pt
10/26/2019, 12:08 AMNothing type, null is the only value of a Nothing? typePablichjenkov
10/26/2019, 12:12 AMstreetsofboston
10/26/2019, 1:04 AMUnit in Kotlin and has only one value Unit.
Passing a null (Unit?) may indeed work as well.
The type Nothing has no values at all (which means you can't create one, get one or pass one). The type Nothing? has only one value (null) and is a sub-type of all other types T? (including Unit?).karelpeeters
10/26/2019, 9:03 AMVoid is more like Kotlin Nothing? than Unit.streetsofboston
10/26/2019, 1:36 PMvoid return Unit in Kotlin. Void is a nullable version of void in Java (much like int vs Integer), which would be Unit? in Kotlin.karelpeeters
10/26/2019, 1:37 PMvoid is nothing like the class Void.streetsofboston
10/26/2019, 1:47 PMVoid is designed, with a private constructor and no public singleton or factory methods returning one, much like the design of Nothing.Pablichjenkov
10/26/2019, 2:34 PMVoid with Emptyness or Nothing. Don't know if the language designers pursued this semantic.
Now as Anton said the fact of java methods returning void needing to return Unit in kotlin makes one to think that they are equivalent.
To me this void -> Unit transformation is basically a trick to bridge an imperative paradigm with a functional paradigm. But when it comes to the typing system itself I am more into Void being more Nothing than Unit.karelpeeters
10/26/2019, 2:59 PMvoid is not like Nothing at all, void simply means a function doesn't return anything but Nothing means it never returns!