mercredi 27 juillet 2016

Why do I have to return Unit.INSTANCE when implementing in Java a Kotlin function that returns a Unit?

If I have a Kotlin function

fun f(cb: (Int) -> Unit)

and I want to call f from Java, I have to do it like:

f(i -> {
     dosomething();
     return Unit.INSTANCE;
});

which looks very ugly. Why can't I just write it like f(i -> dosomething());, since Unit in Kotlin is equivalent to void in Java?

Aucun commentaire:

Enregistrer un commentaire