February 2020
Intermediate to advanced
412 pages
9h 36m
English
When you call the subscribe() method on an Observable, an Observer receives three events—onNext, onError, and onComplete—that are processed by the corresponding methods. Instead of specifying lambda expressions as we were doing earlier, we can implement an Observer and pass an instance of it to the subscribe() method as follows:
import io.reactivex.rxjava3.core.Observable;import io.reactivex.rxjava3.core.Observer;import io.reactivex.rxjava3.disposables.Disposable;public class Ch2_07 { public static void main(String[] args) { Observable<String> source = Observable.just("Alpha", "Beta", "Gamma"); Observer<Integer> myObserver = new Observer<>() { @Override public void onSubscribe(Disposable d) {
Read now
Unlock full access