O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using method references

It is not necessary to return a new lambda every time with the method calls--in lots of cases, we can use method references directly.

We have used this earlier:

.doOnError(showToastErrorNotification())

Instead, we could have as well created a method:

private void showToastErrorNotificationMethod(Throwable error) {    Toast.makeText(this, "We couldn't reach internet - falling back     to local data",            Toast.LENGTH_SHORT)            .show();}

Then, we can replace the .filter() with this:

.doOnError(this::showToastErrorNotificationMethod)

There is very little difference between the two approaches, and it boils down to the personal preference. Usually, calling method, such as in the following case, gives more flexibility to do additional ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required