Backported StreamSupport on Java 7/Android -
i mean library: http://sourceforge.net/projects/streamsupport/
it meant compatible java8 streams, tried run examples java8 docs, this:
intstream.range(1, 4).foreach(system.out::println);
but .range not defined anywhere. library documentation:
streamsupport backport of java 8 java.util.function (functional interfaces) , java.util.stream (streams) api users of java 6 or 7 supplemented selected additions java.util.concurrent didn't exist in java 6.
but: - can't find single example how use backported library - can see, can't use simplest scenario java8.
can give me example how use backported streamsupport, or link documentation?
[edit]
import java8.util.function.consumer; intstreams.range(1, 4).foreach(new consumer<integer>(){ public void accept(integer next){ system.out.println(next); } });
error message:
error:(126, 35) error: method foreach in interface intstream cannot applied given types; required: intconsumer found: > reason: actual argument > cannot converted intconsumer method invocation conversion
if change consumer intconsumer:
error:(127, 59) error: type intconsumer not take parameters
i haven't used library, but, looking @ code (http://sourceforge.net/p/streamsupport/code/ci/default/tree/src/main/java/java8/util/stream/intstreams.java) think should work
import java8.util.stream.intstreams; intstreams.range(1, 4).foreach(system.out::println);
java 7 style
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); } });
updated switched intconsumer. using plain consumer below
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); } });
Comments
Post a Comment