I thought that in Kotlin, Unit
was equivalent to Void
. With Vert.x Service Discovery, it is not possible to pass a Future<Unit>
to unpublish(String id, Handler<AsyncResult<Void>> resultHandler)
(gives a type mismatch) yet it will accept Future<Void>
without any problem. Why is this and is there a solution or will I just have to live with using Void
?
Asked
Active
Viewed 384 times
1

junglie85
- 1,243
- 10
- 30
1 Answers
3
Unit
is not equivalent to Void
, it is equivalent to void
in kotlin.
In java, void
is a keyword, but Void
is a class. so the code below can't be compiled:
fun foo():Void{/**need return a Void instance exactly**/}
fun bar():Void{ return Unit; }
// ^--- type mismatch error
java applies the same rule, for example:
Void canNotBeCompiled(){
// must return a Void instance exactly.
}
Void foo(){
return Void.TYPE;
}
Void nil(){
return null;
}
Finally the Unit documentation also says:
The type with only one value: the Unit object. This type corresponds to the void type in Java.

holi-java
- 29,655
- 7
- 72
- 83
-
Thanks. Yes, you're exactly right. Those pesky capital letters! – junglie85 Jun 27 '17 at 07:07
-
@amb85 Not at all. – holi-java Jun 27 '17 at 07:08