问题描述
所以我今天将Android Studio项目迁移到Java 8,Android API级别24和Jack工具链,以查看新功能,特别是lambdas和 CompletableFuture
。
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
.
不幸的是, CompletableFuture
似乎只能从API级别24开始(我的该项目的最低API级别是16)。
Unfortunately, CompletableFuture
seems to be available only from API level 24 on (my minimum API level for that project being 16).
您知道有关将 CompletableFuture
带到Android支持库的计划吗?它似乎是Promises模式的一个很好的解决方案。
Do you know of any plans on bringing CompletableFuture
to the Android support library? It looks like a nice solution for the Promises pattern.
推荐答案
项目在 streamsupport-cfuture中提供 CompletableFuture
的后端可用于Android开发的组件,在所有设备上都支持。
The streamsupport project provides a backport of CompletableFuture
in its streamsupport-cfuture
component which can be used for Android development, supported on all devices.
使用
dependencies {
compile 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.0'
}
或更现代的Android Studio 3.x前叉
or the more modern fork for Android Studio 3.x
dependencies {
compile 'net.sourceforge.streamsupport:android-retrofuture:1.7.0'
}
如果你想使用Android Studio 3.x desugar工具链。
if you want to use the Android Studio 3.x desugar toolchain.
CompletableFuture的新Java 12异常处理方法已集成在1.7.0版本中
The new Java 12 exception handling methods for CompletableFuture JDK-8211010 have been integrated in release 1.7.0
这篇关于Android支持库中的CompletableFuture?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!