The easiest way to check is entity == null
. There is no shorter way to do that.
Note that there is a method for this in the standard lib:
And another one which is the opposite of the above one:
And there is yet another one which can be used to force a value to be not null
, it throws a NullPointerException
otherwise:
T Objects.requireNonNull(T obj);
Note: The Objects class was added in Java 7, but the isNull()
and nonNull()
methods were added only in Java 8.