Difference between 'same' and 'eq' in EasyMock

末鹿安然 提交于 2019-12-22 01:58:22

问题


Is there a significant(or even any) difference between 'same' and 'eq' in EasyMock?


回答1:


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).

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.

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).




回答2:


same uses == and equals uses .equals()



来源:https://stackoverflow.com/questions/6654734/difference-between-same-and-eq-in-easymock

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!