I created a function to filter with multiple predicates for which I perform a logical AND for them:
@SafeVarargs
public static <T> Stream<T> filter(Stream<T> source, Predicate<T>... predicates) {
return source.filter(Arrays.stream(predicates).reduce(predicates[0], Predicate::and));
}
When calling:
filter(IntStream.range(0, 10).boxed(), x -> x % 2 != 0, x -> x%3 == 0).forEach(System.out::println);
It works fine and prints 3 and 9. However when I pass a single predicate such as:
filter(IntStream.range(0, 10).boxed(), x -> x % 2 != 0).forEach(System.out::println);
I get a compilation error:
The target type of this expression must be a functional interface
Why is this?
For infos I use Eclipse Luna version 1.