RxJava: 2.x Emit null reference item using Observable.just

Hi.

In RxJava 1.x I use Observable.just(null) when I need to create an Observable which emits a null reference. I use this approach in some unit tests as such as when the parameterized Type is Void (Observable<Void>).

But now there is a precondition when calling Observable#just which forces to the supplied item to not be a null reference.

So, how can I create an Observable which emits a null reference?

Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

You can’t. The Reactive-Streams specification forbids nulls thus we don’t allow that either. If you don’t have any value, use Completable.

Note that, although Void type parameters are allowed, having a Subject<Void> would be useless as you could not call onNext on it. null is the only inhabitant of the Void type and null is not allowed anywhere - even in subjects.