Convert kotlin predicate to java

386 Views Asked by At

How do you convert this Kotlin predicate to java:

List<SomeObjWithProp> lst = ...
Iterables.filter(lst) { obj -> obj?.property != null }
1

There are 1 best solutions below

0
On BEST ANSWER

Java has lambda expressions but not a safe-navigation operator, so you'll need to expand the null check explicitly:

Iterables.filter(lst, obj -> (obj != null && obj.getProperty() != null));