Using streamsupport with a Java 7 javac
compiler I encounter the following compile error:
[ERROR] method map in interface java8.util.stream.Stream<T> cannot be applied to given types; [ERROR] required: java8.util.function.Function<? super java.lang.Object,? extends R>
[ERROR] found: <anonymous java8.util.function.Function<java.lang.Integer,java.lang.String>> [ERROR] reason: no instance(s) of type variable(s) R exist so that argument type <anonymous java8.util.function.Function<java.lang.Integer,java.lang.String>> conforms to formal parameter type java8.util.function.Function<? super java.lang.Object,? extends R>
My code is
List<Object> listSum = RefStreams.iterate(0, new UnaryOperator<Integer>() {
@Override
public Integer apply(Integer n) {
return n+1;
}
}).limit(10000).map(new Function<Integer,String>() {
@Override
public String apply(Integer n) {
return String.format("%04d", n);
}
}).collect(Collectors.toList());
I want to know what to do and why this error occurred? Thanks