zoukankan      html  css  js  c++  java
  • 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);
        }
    }
    
  • 相关阅读:
    1320. Graph Decomposition 夜
    1156. Two Rounds 夜
    1176. Hyperchannels 夜
    1227. Rally Championship 夜
    1450. Russian Pipelines 夜
    1137. Bus Routes 夜
    找回c盘空间
    IDOC
    .落叶无痕水无声
    真正写的第一篇博客吧
  • 原文地址:https://www.cnblogs.com/feiqiangsheng/p/15224057.html
Copyright © 2011-2022 走看看