Boolean != false

Bart van Heukelom picture Bart van Heukelom · Nov 30, 2010 · Viewed 46.4k times · Source

In Java, you would usually say that

if(someBool != false)

is the same as

if(someBool)

But what if someBool is not of type boolean but Boolean, and its value is null?

Answer

Michael Borgwardt picture Michael Borgwardt · Nov 30, 2010

If you want to handle Boolean instances as well as primitives and be null-safe, you can use this:

if(Boolean.TRUE.equals(someBool))