0
A
回答
0
不,没有任何区别。
'不等于'(!=
)是山姆不是'等于'。
0
这里没有什么不同,!(obj == null)只是写入(反向)的另一种方式,而且它比第一个难以理解。
0
没有任何区别。大多数人更容易阅读(obj != null)
。
3
在运行时,的
==
结果是true
,如果操作数的值都为null
或两者指代相同的对象或阵列;否则,结果是false
。如果操作数值都是null
或者两者都引用同一对象或数组;否则,结果是true
。
而且JLS Sec 15.15.6,其描述了逻辑补运算符(!
):
在运行时,操作数是受取消装箱转换(§5.1.8)如果需要的话。如果(可能转换后的)操作数值为
false
,并且false
(如果可能转换的)操作数值为true
,则一元逻辑补码表达式的值为true
。
所以从评估的角度来看,两者是完全一样的;但!=
更容易阅读。
0
NO区别。
此外,有些人更喜欢null
彼此靠近,同时进行条件检查。
if(obj1 == null || null == obj2) // looks better to read
...
if(obj1 == null && obj.method()) // have high chances to throw an exception
even if True && this will be checked
if(obj1 == null || obj.method()) // is preferred over the above one
if True || this will be NOT be checked
相关问题
- 1. ReferenceEquals(null,obj)与null == obj相同吗?
- 2. != null和!== null之间有什么区别?
- 3. iphone中obj = nil和[obj removeFromSuperview]的区别?
- 4. undefined和null之间有什么区别?
- 5. 'const Obj'和'Obj&'有什么关系?
- 6. 这些(bCondition == NULL)和(NULL == bCondition)之间有什么区别?
- 7. null和System.DBNull.Value有什么区别?
- 8. TAggregateField.IsNull和(TAggregateField.Value = Null)有什么区别
- 9. Null,Nil和Nothing有什么区别?
- 10. NULL和NULL中的空值有什么区别
- 11. Scala中a.ne(null)和!= null有什么区别?
- 12. .LIB和.OBJ文件有什么区别? (Visual Studio C++)
- 13. ActionScript中obj [name]和obj.name有什么区别?
- 14. obj c函数中(+)和( - )运算符有什么区别
- 15. object x = null和object x =(object)null有什么区别?
- 16. “foo is null”和“foo == null”有什么区别
- 17. “x is null”和“x == null”有什么区别?
- 18. Obj-C对象为null
- 19. C# - 这是检查有必要“obj是人&& OBJ!= NULL”
- 20. javascript obj.onclick和prototype的Event.observe(obj,'click',fn)有什么区别?
- 21. obj和obj.hasOwnProperty(prop)和obj [prop]之间的区别?
- 22. <foo></foo>和JAXB中的null有什么区别?
- 23. PHP中NULL和null之间的区别
- 24. NaN和Inf以及R中的NULL和NA有什么区别?
- 25. 为什么String.Equals(Object obj)检查这个== null?
- 26. 在WPF中,RenderTransform的null和Identity有什么区别?
- 27. R中的NULL和字符(0)有什么区别?
- 28. 使用EndOfStream和检查null有什么区别?
- 29. JavaScript:Reflect.get()和obj ['foo']之间的区别
- 30. JavaScript:if(!x)`和if(x == null)`有什么区别?
简答:没有。长答案:不。 –
'!(obj == null)'比'(obj!= null)'更难读取。前者有点像yoda-esque。 –
'true'和'!false'有什么区别吗? –