开发者

Difference between 'same' and 'eq' in EasyMock

开发者 https://www.devze.com 2023-03-20 00:45 出处:网络
Is there a significant(or even any) difference between \'sam开发者_JS百科e\' and \'eq\' in EasyMock?same checks if both objects are actually the same instance (reference equality). eq calls equals and

Is there a significant(or even any) difference between 'sam开发者_JS百科e' and 'eq' in EasyMock?


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


same uses == and equals uses .equals()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号