RxJava How to Subscribe to an Observation Item

The documentation says that the object is an observer and can subscribe to Observables, but I cannot find a way to do this in the code.

Thanks in advance!

+4
source share
1 answer

Unit code example:

@Test
public void shouldSubscribeToSubjectToObservable() throws InterruptedException {
    Observable<Integer> observable = Observable.just(1, 2);
    PublishSubject<Object> subject = PublishSubject.create();
    subject.subscribe(o -> {
        System.out.println("o = " + o);
    });

    observable.subscribe(subject);

    Thread.sleep(1000);
}  
+4
source

All Articles