我想创建将 Predicate::and 合并到一个谓词中的方法,并将其提交到输入列表中。我有代码:
public static List<?> getFilteredList(Collection<?> collection, Collection<Predicate<?>> filters) {
return collection.stream()
.filter(filters.stream().reduce(Predicate::and).orElse(t -> true))
.collect(Collectors.toList());
}
Run Code Online (Sandbox Code Playgroud)
但是编译器说有一个错误 Predicate::and
Incompatible types: Predicate<capture of ?> is not convertible to Predicate<? super capture of ?>
如何解决?