I need to create a stream operation with a predicate based on a boolean function. A workaround was found by reorganizing the method argument as a predicate, as shown:
public <T> Predicate<T> pred(final Predicate<T> aLambda) { return aLambda; } public List<String> foo() { return new ArrayList<String>().stream()
The 'pred' method does not seem to do anything, but not this:
public List<String> foo() { return new ArrayList<String>().stream() .filter((String::isEmpty).negate()) .collect(Collectors.toList()); }
and no built-in conversion:
public List<String> foo() { return new ArrayList<String>().stream() .filter(((Predicate)String::isEmpty).negate()) .collect(Collectors.toList()); }
seems to work. Error with error
The target type of this expression must be a functional interface.
What bizarre conversion happens in the pred (...) method?
java java-8 functional-interface predicate
Tomas F.
source share