是否可以在Android API上使用Java 8 Stream API< 24? [英] Is it possible to use the Java 8 Stream API on Android API < 24?

查看:1444
本文介绍了是否可以在Android API上使用Java 8 Stream API< 24?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过这个发布。但是我仍然无法在minSdkVersion<上运行包含Java 8 Stream API功能的代码,如下所示: 24。

I've read this post here. But still I cannot run code containing Java 8 Stream API features like the following on minSdkVersion < 24.

List<Car> newCars = cars.stream()
                        .filter(s -> s.getColor().equals("red"))
                        .collect(Collectors.toList());

由于错误消息,这不会运行

This doesn't run due to the error message


调用需要API级别24(当前最小值为15):java.util.Collection #stream

Call requires API level 24 (current min is 15): java.util.Collection#stream

那么有人知道解决方案吗?

So does someone know a solution?

推荐答案

您不能在API级别上使用Java8流< 24。

You can not use Java8 streams on API level < 24.

然而,有一些库反向移植了一些流功能

However, there are some libraries that backport some of the stream functionality

https://github.com/aNNiMON/Lightweight-Stream-API

https://github.com/konmik/solid

< a href =https://sourceforge.net/projects/streamsupport/> https://sourceforge.net/projects/streamsupport/ (@sartorius在评论中提到)

https://sourceforge.net/projects/streamsupport/ (mentioned by @sartorius in comment)

这篇关于是否可以在Android API上使用Java 8 Stream API&lt; 24?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆