0

I am using RxBinding for Android widgets. I would like to do the following: Observable<java.lang.Void> obs = RxView.clicks(button);
But I get a compile time error saying that the expected type is kotlin.Unit. RxView.clicks(button) returns an Observable<Unit>but I don't think that Java has a Unit datatype.
How do I get an Observable<Void> in Java?

Shankha057
  • 1,296
  • 1
  • 20
  • 38

1 Answers1

1

You can live with Observable<Unit> in Java. kotlin.Unit is a class file available for java programs as soon as kotlin-stdlib-<some version>.jar is in your class path, and it is there already because it is required by RxBinding.

If, however, some other part of your program requires Observable<Void>, it can be obtained with:

 Observable<Unit> ou = RxView.clicks(button);
 Observable<Void> ov = ou.as(unit->null);
Alexei Kaigorodov
  • 13,189
  • 1
  • 21
  • 38
  • It looks like RxBinding library uses RxJava 1. I am trying to get a `Single` out of it and hence I thought that it would be better to have a `Void` type. – Shankha057 Jan 07 '19 at 12:08