null == object和object == null之间的区别 [英] Difference between null==object and object==null
问题描述
我想知道上述比较之间的差异?
当我检查 object.getItems == null
。
但是如果我把它改为 null == object.getItems()
,它工作得很好。
我曾经调查过这个 null != object and object!= null
但我没有得到满意的答案。
(类似问题:哪个更有效: if(null == variable)or if(variable == null)?)
null == object and object == null
没有语义上的差异。
object.getItems()== null
和 null == object.getItems()
p>
也许你正在混淆的是
nonNullObj。 equals(obj)
和
obj.equals(nonNullObj)
第二选择可以导致NPE,以防被调用者为空)。
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)?)
Difference between null==object and object==null
There is no semantical difference.
object.getItems() == null
and null == object.getItems()
are equivalent.
Perhaps you're mixing it up with the fact that
nonNullObj.equals(obj)
and
obj.equals(nonNullObj)
can make a difference (since the second alternative could result in a NPE in case the callee is null).
这篇关于null == object和object == null之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!