EasyMock中“ same”和“ eq”之间的区别 [英] Difference between 'same' and 'eq' in EasyMock
问题描述
EasyMock中的 same和 eq之间是否存在显着(甚至任何)差异?
Is there a significant(or even any) difference between 'same' and 'eq' in EasyMock?
推荐答案
same
检查两个对象是否实际上是同一实例(引用相等)。 eq
调用 equals
,因此检查两者是否具有相同的值(值相等)。
same
checks if both objects are actually the same instance (reference equality). eq
calls equals
and therefore checks if both have the same value (value equality).
请记住,默认 equals
实现在内部使用 ==
,因此<如果您使用的类没有适当的,则code> eq
的作用与相同
相同等于覆盖。
Keep in mind that the default equals
implementation uses ==
internally, and therefore eq
will do the same as same
if you're using classes that do not have a proper equals
override.
但是,最好还是使用 same
来声明您的意图。表示引用相等, eq
表示值相等。它还可能有助于您发现错误(即发现您忘记覆盖等于
)。
But still, it's better to state your intent by using same
for reference equality and eq
for value equality. It might also help you finding bugs (i.e. finding that you forgot to override equals
).
这篇关于EasyMock中“ same”和“ eq”之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!