🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### 2.4.2 Predicate复合 谓词(Predicate)接口包括negate、and和or,可以通过已有的谓词组合出更复杂的谓词。 - **nagate**:取反 - **and**:且 - **or**:或 ```java import java.util.function.Predicate; public class ComplexPredicateTest { public static void main(String[] args) { Predicate<Model> p1 = m -> { String name = m.getName(); return name != null && name.startsWith("张"); }; Predicate<Model> p2 = m -> { Integer height = m.getHeight(); return height != null && height > 100; }; Predicate<Model> p = p1.and(p2); } static class Model { private Integer height; private String name; public Integer getHeight() { return height; } public void setHeight(Integer height) { this.height = height; } public String getName() { return name; } public void setName(String name) { this.name = name; } } } ```