How to replace "!= null" statement with method reference?

DIBits :

My Intelij shows me that I can replace the lambda .filter(bean -> bean != null) with a method reference. Its is obviuos for me how to do it when I have a Class or an Object with methods. But how to do a reference on != null, is there a Class that has some kind of isNull() method?

Ousmane D. :

This is the exact reason why the Objects::nonNull API exists:

.filter(Objects::nonNull);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=111095&siteId=1