Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CompletableFuture in the Android Support Library?

Tags:

So I was migrating an Android Studio project to Java 8, Android API level 24 and the Jack toolchain today to check out the new features, especially lambdas and CompletableFuture.

Unfortunately, CompletableFuture seems to be available only from API level 24 on (my minimum API level for that project being 16).

Do you know of any plans on bringing CompletableFuture to the Android support library? It looks like a nice solution for the Promises pattern.

like image 959
Thomas Wana Avatar asked Jul 06 '16 10:07

Thomas Wana


2 Answers

The streamsupport project provides a backport of CompletableFuture in its streamsupport-cfuture component which can be used for Android development, supported on all devices.

Either use

dependencies {     implementation 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.4' } 

or the more modern android-retrofuture fork for Android Studio >= 3.x

dependencies {     implementation 'net.sourceforge.streamsupport:android-retrofuture:1.7.4' } 

if you can use Android Studio 3.x and above.

The new Java 12 exception handling methods for CompletableFuture JDK-8211010 have been integrated in release 1.7.0

For users who want a minimal dependency footprint there is also a 105 KiB minifuture variant which is a "stripped to the bones" version of streamsupport-cfuture.

dependencies {     implementation 'net.sourceforge.streamsupport:streamsupport-minifuture:1.7.4' } 

This has no dependencies and provides only the minimum API necessary to use CompletableFuture and nothing else (no Streams, no public ForkJoinPool and such).

like image 175
Stefan Zobel Avatar answered Oct 23 '22 11:10

Stefan Zobel


streamsupport library mentioned in Stefan Zobel's answer was forked especially for Android Studio >=3.0 desugar toolchain, please check android-retrofuture

like image 24
fobo66 Avatar answered Oct 23 '22 09:10

fobo66