Why there is no isNull method in Java object class

I wonder why there is no conventional method for checking a null value at the level of a Java object. What is the problem if the java.lang.Object class had an isNull method to check for a null value.

+3
java isnull
source share
3 answers

There is no reason for this, you are checking null as oleksii declared ...

if (foo == null) { } 
+9
source share

This is a reasonable question as @jsn notes, but in Java World, the idea of isNull is similar to the isTrue method. Just because Microsoft does this does not make it a good idea .;)

isNull can only return false, since you can only call a method for a reference other than null. Therefore, if you can call isNull , it must be false.

+4
source share

The isNull method isNull not make sense, since you need to call it on an object. But if you do not have an object (because it is null ), you cannot call it.

+3
source share

All Articles