February 2020
Intermediate to advanced
412 pages
9h 36m
English
Implementing Observer is a bit verbose and cumbersome. Thankfully, the subscribe() method is overloaded to accept lambda arguments for our three events. This is likely what you will want to use in most cases. You can specify three lambda expressions separated by commas: the onNext lambda, the onError lambda, and the onComplete lambda. For our previous example, we can change it to look as follows:
Consumer<Integer> onNext = i -> System.out.println("RECEIVED: " + i);Consumer<Throwable> onError = Throwable::printStackTrace;Action onComplete = () -> System.out.println("Done!");
We can pass these three lambdas as arguments to the subscribe() method, and it will use them to implement an Observer for us. This is much ...
Read now
Unlock full access