我是说这个图书馆:http://sourceforge.net/projects/streamsupport/
它意味着与Java8流兼容,因此我尝试从Java8文档中运行一些示例,如下所示:
IntStream.range(1, 4).forEach(System.out::println);但是.range在任何地方都没有定义。从图书馆的文件中:
streamsupport是Java8 java.util.function (功能接口)和java.util.stream (streams) API的后端,用于Java6或7的用户,补充了来自java.util.concurrent的一些附加内容,这些添加在Java6中并不存在。
但是:-我找不到如何使用这个支持库的任何一个例子--正如您所看到的,我也不能使用来自Java8的最简单的场景。
有人能给我举一些例子,如何使用支持的StreamSupport,或一些链接到文档吗?
编辑
import java8.util.function.Consumer;
IntStreams.range(1, 4).forEach(new Consumer<Integer>(){
public void accept(Integer next){
System.out.println(next);
}
});错误消息:
错误:(126,35)错误:接口forEach中的方法IntStream不能应用于给定类型;必需: IntConsumer查找:>原因:实际参数>不能通过方法调用转换转换为IntConsumer
如果我将使用者改为IntConsumer:
错误:(127,59)错误: IntConsumer类型不接受参数
发布于 2015-09-21 13:47:13
我还没有使用过这个库,但是,看看代码(http://sourceforge.net/p/streamsupport/code/ci/default/tree/src/main/java/java8/util/stream/IntStreams.java),我认为应该可以
import java8.util.stream.IntStreams;
IntStreams.range(1, 4).forEach(System.out::println);Java 7风格
import java8.util.stream.IntStreams;
import java8.util.function.IntConsumer;
IntStreams.range(1, 4).forEach(new IntConsumer(){
public void accept(int next){
System.out.println(next);
}
});更新切换到IntConsumer。使用下面的普通消费者
import java8.util.stream.IntStreams;
import java8.util.function.Consumer;
IntStreams.range(1, 4)
.boxed()
.forEach(new Consumer<Integer>(){
public void accept(Integer next){
System.out.println(next);
}
});https://stackoverflow.com/questions/32694291
复制相似问题