EasyMock中“ same”和“ eq”之间的区别 [英] Difference between 'same' and 'eq' in EasyMock

查看:259
本文介绍了EasyMock中“ same”和“ eq”之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 sameif 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆