Our project changed the object existence checks from foo == null or foo != null to Objects.isNull(foo) or Objects.nonNull(foo). I never got an explanation why that should be better, that's why I ask.

I’ve been programming in Pascal, C, Perl, Java for a long time and have always checked for inequality with !=. This systax is pretty common and any programmer who sees it knows what it does right away. Now we have a function where at least when you see it for the first time you have to check what it is actually doing (similar to C++, but I see that as a deterioration). I’ll admit, I still think that calling a function is an extra jump in the program, there has to be an extra element on the stack, I know compilers can inline that these days, but it still seems strange to me for a basic function to call a one-line function that only encapsulates this function. That change was a year and a half ago and I still stumble over it. The Javadoc comments on the function: “This method exists to be used as a Predicate” but it leaves me alone, which is the advantage of using this function everywhere.

So I would like to ask what are the advantages of this approach? Is it a better object-oriented style? Does it have any benefit in debugging, unit testing, static code analysis, or does it matter in another context?


Ask the people who made the change in your project.

I'm with you, there is no advantage to doing this everywhere, and the Javadoc pretty much implies it as well - the methods were created to be used via method references.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.