Java Predicate 接口

使用示例

public class Test {
    public static void main(String args[]) {
        Predicate<String > p = (str)->{return Objects.equals("费哥哥", str);};
        System.out.println(p.test("费哥哥")); 
    }
}

结果:
true

predicate 源码

package java.util.function;
import java.util.Objects;
/**
 * 断定型接口。
 */
@FunctionalInterface
public interface Predicate<T> {
    boolean test(T t);

    default Predicate<T> and(Predicate<? super T> other) {
        Objects.requireNonNull(other);
        return (t) -> test(t) && other.test(t);
    }

    default Predicate<T> negate() {
        return (t) -> !test(t);
    }

    default Predicate<T> or(Predicate<? super T> other) {
        Objects.requireNonNull(other);
        return (t) -> test(t) || other.test(t);
    }

    static <T> Predicate<T> isEqual(Object targetRef) {
        return (null == targetRef)
                ? Objects::isNull
                : object -> targetRef.equals(object);
    }
}
原文地址:https://www.cnblogs.com/feiqiangsheng/p/15224057.html