Hi I would like to know diff between the above comparisons?
I am getting null pointer exception when I check object.getItems() == null.
But if I change it to null == object.getItems(), it workes fine.
I did look into this what is the difference between null != object and object!=null
But I didnt get satisfactory answer.
(Similar question: Which is more effective: if (null == variable) or if (variable == null)?)
There is no semantical difference.
object.getItems() == nullandnull == object.getItems()are equivalent.Perhaps you’re mixing it up with the fact that
and
can make a difference (since the second alternative could result in a NPE in case the callee is null).