(obj == null)vs(null == obj)? [英] (obj == null) vs (null == obj)?
问题描述
我的老板说我应该使用 null == obj
,因为它比 obj == null
他不记得为什么要这样做。是否有任何理由使用 null == obj
?
我觉得它在某种程度上...对面!
My boss said I should use null == obj
, because it's better than obj == null
, but he didn't remember why to do this. Is there any reason for using null == obj
?
I feel it somehow... opposite!
在Google上进行一些搜索之后,我发现的唯一的东西是:
After some search on Google, the only thing I found is:
推荐答案
而是通过键入 obj = null
将 obj
然而,这是从C时代的回忆,在java中,这是不可能的,因为 =
表达式返回赋值的右边。因为 null
不是 boolean
,编译器会抱怨。
You can't accidently assign null
to obj
by typing obj = null
instead. However, that's a reminiscence from C times, in java, it is not possible, as the =
expression returns the right hand side of the assignment. As null
is not a boolean
, the compiler will complain.
我会尝试向我的老板解释一次,展示它。如果他仍然不同意你的话,只要这样做。这是一个与你的老板打架的小东西。
I would try to explain it to my boss once, demonstrate it. If he still doesn't agree with you, just do it. It's a petty thing to fight about with your boss.
这篇关于(obj == null)vs(null == obj)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!