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)
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 aSubject<Void>
would be useless as you could not callonNext
on it.null
is the only inhabitant of theVoid
type andnull
is not allowed anywhere - even in subjects.