Observable which does not pass anything in onNext()

前端 未结 6 954
猫巷女王i
猫巷女王i 2021-02-02 06:52

I would need an Observable, for example to provide a system clock, which does not need to pass anything in onNext(). I couldn\'t find a signature that would allow me to do that.

6条回答
  •  情深已故
    2021-02-02 07:17

    RxJava 2 Wiki:

    RxJava 2.x no longer accepts null values and the following will yield NullPointerException immediately or as a signal to downstream.

    ...

    This means that Observable can no longer emit any values but only terminate normally or with an exception. API designers may instead choose to define Observable with no guarantee on what Object will be (which should be irrelevant anyway)

    It means that you can't use Void and do Observable.just(null).

    Use Object or some other simple type instead:

    Observable.just(new Object());
    

    提交回复
    热议问题