import java.util.function.Predicate; class Foo { public Foo(Predicate p) { } void m(Predicate p){ new Foo<>(p == null ? null : acc -> p.test(acc)); new Foo<>(acc -> p.test(acc)); } }