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?

4

1 回答 1

1

您可以使用Observable<Unit>Java。kotlin.Unit是一个类文件,只要kotlin-stdlib-<some version>.jar在你的类路径中,它就可以用于 java 程序,并且它已经存在,因为它是 RxBinding 所必需的。

但是,如果您的程序的某些其他部分需要Observable<Void>,则可以通过以下方式获得:

 Observable<Unit> ou = RxView.clicks(button);
 Observable<Void> ov = ou.as(unit->null);
于 2019-01-07T06:50:40.530 回答