Backported StreamSupport on Java 7 / Android

I mean this library: http://sourceforge.net/projects/streamsupport/

It must be compatible with Java8 threads, so I tried to run some examples from Java8 docs, for example:

IntStream.range(1, 4).forEach(System.out::println);

But .range is not defined anywhere. From this library documentation:

streamsupport is the backport of the Java 8 interface java.util.function (functional interfaces) and java.util.stream (streams) for Java 6 or 7 users supplemented with selected add-ons from java.util.concurrent, t exists in Java 6.

But: - I can not find a single example of how to use this backported library - As you can see, I also can not use even the simplest script from Java8.

Can someone give me an example of how to use backported StreamSupport or some documentation link?

[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: the method for each in the IntStream interface cannot be applied to these types; required: IntConsumer found:> reason: actual argument> cannot be converted to IntConsumer using call conversion

If I change Consumer to IntConsumer:

Error: (127, 59) error: type IntConsumer does not accept parameters

+4
source share
1 answer

, , (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);
                }
});
+5

Source: https://habr.com/ru/post/1608314/


All Articles