开发者

Overload the equals method in java [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Best practices regarding equals: to overload or not to overload?

Does anyone overload the equals method in java? The overloaded method will be

public boolean equals(final MyClass myClass)

This will have the benefit of having the relevant comparison part (guts of the method) in another method. Details are in开发者_开发知识库 my blog.

EDIIT : This is a genuine question. Link to the blog entry removed.


IMO, it would be a bad idea because it would be liable to confuse someone reading your code. I'd never do it.

If it becomes necessary to provide an "equality" method that does not override boolean equals(Object), it is a much better idea to give it a different method name.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜