what is the difference between null != object and object!=null
Possible Duplicates:
which way is better null != object or object != null?
Why does one often see null != variable instead of variable != null in C#?
‘ … != null or ‘null != … best performance?
请指导我。
null!= object和object!= null有什么区别
对于" .equal(" something")和" something" .equals(")相同
哪一种适合加工。
前两个是等效的,但是" null!= object"是一种古老的惯例,在这种语言中,可以有效地编写" if(object = null)"并意外地将null分配给该对象。 这是防止事故发生的警卫。
第二个等效项具有一个附加的优点,即如果" something"为null,则不会获得null引用异常,而如果这样做,则为:something" .equals(")。
语义或性能绝对没有区别。
在这种情况下,
JLS 15.21.3 Reference Equality Operators == and !=
If the operands of an equality operator are both of either reference type or the null type, then the operation is object equality.
The result of
!= isfalse if the operand values are bothnull or both refer to the same object or array; otherwise, the result istrue .
使用最易读的内容。 通常是
相关问题
- ‘…!=空'或‘null!=…"最佳性能?