如何理解里面的and/or等函数
default Predicate<T> and(Predicate<? super T> other) {
Objects.requireNonNull(other);
return (t) -> test(t) && other.test(t);
}
/**
* Returns a predicate that represents the logical negation of this
* predicate.
*
* @return a predicate that represents the logical negation of this
* predicate
*/
default Predicate<T> negate() {
return (t) -> !test(t);
}
我自己写了个函数式接口,怎么理解一目了然
return 返回的都是preDicate这个函数式接口(使用lambda表达式推导)
lambda表达式的基本表示方法: (函数参数)-> { 函数体};
如果只有一个返回语句可以省略花括号
@FunctionalInterface
public interface myPredicate<T> {
boolean test(T t);
default myPredicate<T> and(myPredicate<T> other) {
return (t) -> { return test(t) && other.test(t); };
}
}
即:return (t) -> test(t) && other.test(t);
等价于: return (t) -> { return test(t) && other.test(t); };