Skip to content
Advertisement

What is the meaning of flatmap( return Observer::onComplete;) in rxJava? And why is the return type of it is Observerable?

Observable<POJO> localRequest = Database.getInstance(this.context).getAllQuestions().flatMapObservable((questions) -> {
         ContentHolder.getHolder().setQuestionMap(questions);
         return Observer::onComplete;
     });

 public Maybe<Question[]> getAllQuestions () {
     
 }

I cannot understand the line of return Observer::onComplete;

Advertisement

Answer

It’s a fancy and incorrect way of doing an empty result รก la Observable.empty().

fatMapObservable expects an Observable<POJO> as its return due to target typing. Since Observable is a single abstract method type, you can use a lambda expression to construct an instance of it. I.e., have the subscribe(Observer<POJO>) method implemented via observer -> observer.onComplete() or Observer::onComplete.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement