企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 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; } } } ```