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 应用程序中,但它仍然不起作用.在android中找不到方法stream().
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.).Collection 接口上添加的默认方法(例如#stream()、#forEach())可从单独的实用程序类中获得,例如可迭代对象或 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屋!