我无法理解两个相同的事物和两个相同的事物之间的概念.令我困惑的是声明"两个对象可以是相同的,这意味着它们是相同的.但是,两个相等的对象并不相同." 请有人帮我理解差异吗?谢谢.
在objective-c,略微伪代码......
NSString * a = @"hello";
NSString * b = @"hello";
a == a //they are identical (the same object)
[a isEqualToString:a]; //they are equal.
a != b //Even though the string contents are the same they are not the same object.
[a isEqualToString:b]; // they aren't identical but they are equal.
Run Code Online (Sandbox Code Playgroud)
关于这个主题的一篇很长很好的博客文章,请看这个
http://www.karlkraft.com/index.php/2008/01/07/equality-vs-identity/
| 归档时间: |
|
| 查看次数: |
1856 次 |
| 最近记录: |