obj.nil?与 obj == nil [英] obj.nil? vs. obj == nil
本文介绍了obj.nil?与 obj == nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 obj.nil 更好吗?
还是 obj == nil
两者的好处是什么?
Is it better to use obj.nil?
or obj == nil
and what are the benefits of both?
推荐答案
使用 obj.nil 更好吗?或 obj == nil
完全一样. 它具有完全相同的从外部观察到的效果 ( pfff ) *
It is exactly the same. It has the exact same observable effects from the outside ( pfff ) *
以及两者的好处是什么.
如果你喜欢微优化所有对象将返回 false
到 .nil?
消息,除了对象 nil
本身,而使用 ==
消息的对象将执行微小的微比较与另一个对象确定它是否是同一个对象.
If you like micro optimizations all the objects will return false
to the .nil?
message except for the object nil
itself, while the object using the ==
message will perform a tiny micro comparison
with the other object to determine if it is the same object.
* 查看评论.
这篇关于obj.nil?与 obj == nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文