Java meets Promises — Functional Java

Yannick S
Yummypets Developers
1 min readOct 15, 2015

Coming from a JavaScript background, dealing with asynchronous processes in Android proved itself to be really cumbersome.

Using anonymous classes to a handle success and error cases right inside the view layer led to a huge mix of classes, empty methods, and undeletable dead code really quickly.

What I missed the most was :

  • Anonymous functions
  • Promises

My first resolution was to install RetroLambda by @orfjackal and embrace the future of Java using lambda expressions !

And then a new baby was born …

… Introducing Promiser

Promiser is a small library written in Java 8 and aiming to simplify making asynchronous processes and handling success/error callbacks.
Inspired by JavaScript Promises specification and AngularJS $http service, Promiser lets you write code in a more functional way.

You can now handle result and error cases like this :

Promiser library is available on Github for Vanilla Java and Android.

We’ve got some ideas planned for the future development of Promiser (for example implementing the .then(…) syntax, so feel free to help us out! 😉

--

--