您的位置:首页 > 编程语言 > Java开发

Java compareTo, equals and hashcode

2013-03-23 03:07 585 查看
Last time, when our team reviewed my code, they pointed several problems of my code. I'm really happy to learn from them. Until now, what I do is only to make the code work. Then, I'll try to refactor it as well as I can. The lack of comprehensive knowledge
in Java blocks me to write effective and clean code. After that, I start learning Java again to know more effective way.

I started learning from http://www.javapractices.com. This is a good website to learn Java.

Today I take a look at compareTo, equals and hashcode. Because one of our project need to use Object as key, I only override compareTo, I didn't know we still need to override equals. And when we override equals, we need to override hashcode. After I take
a look at those three concepts, I know clearly about it.

Here is the references of them:

CompareTo: http://www.javapractices.com/topic/TopicAction.do;jsessionid=A5F619613C75E732660049F98FB09B13?Id=10

equals: http://www.javapractices.com/topic/TopicAction.do;jsessionid=A5F619613C75E732660049F98FB09B13?Id=17

hashcode: http://www.javapractices.com/topic/TopicAction.do;jsessionid=A5F619613C75E732660049F98FB09B13?Id=28
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: