Java compareTo, equals and hashcode

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值