The following statement, although meaningless, seems syntactically sound.
final Stream<LongStream> foobar = IntStream.empty()
.flatMap(x -> IntStream.empty()
.mapToObj(y -> IntStream.empty()
.mapToLong(z -> 1)));
However, it does not compile, returning:
java: incompatible types: invalid return type in lambda expression there is no instance (s) of type (s) of type U, so java.util.stream.Stream corresponds to java.util.stream.IntStream
However, if you delay the tablet, everything works fine:
final Stream<LongStream> foobar = IntStream.empty()
.mapToObj(x -> IntStream.empty()
.mapToObj(y -> IntStream.empty()
.mapToLong(z -> 1)))
.flatMap(x -> x);
What is the difference between .mapToObj(..).flatMap(..)and simple .flatMap(..)? Is there a way to eliminate the extra tablet?
source
share