stream()方法在Android中不工作 [英] stream() method does not work in android
问题描述
如何将此语句从经典java转换为android
How can I convert this statement from classic java to android
Collection<Integer> p1;
int sum = p1.stream().mapToInt(Integer::intValue).sum();
我将Java 8和lambda集成到我的Android应用程序,但它仍然不工作。方法stream()在Android中找不到。
I integrate Java 8 and lambda to my android application, but it still does not work. The method stream() does not found in android.
你能帮我吗?
推荐答案
您可以使用 streamsupport 库,它将流API退回到Java 6/7,可以用于Android开发,所有设备都支持。
You can use the streamsupport library which backports the stream API to Java 6/7 which can be used for Android development, supported on all devices.
Afaik库完全反向存在于Java 8中的原始实现,并使其在单独的包(前缀java8。)中可用。集合接口上添加的默认方法(例如#stream(),#forEach())可从单独的实用程序类获得,例如。 Iterables或StreamSupport。
Afaik, this library fully backports the original implementation present in Java 8 and makes it available in a separate package (prefix java8.). The added default methods on the Collection interface (e.g. #stream(), #forEach()) are available from separate utility classes, e.g. Iterables or StreamSupport.
这篇关于stream()方法在Android中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!