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
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
相关文章推荐
- How to implement equals() and hashCode() methods in Java[reproduced]
- java继承中的 equals + hashCode+toString
- Working with hashCode and equals methods in java
- Java equals() and hashCode() Contract
- Equals and Hash Code in Java(Sun认证重点试题)
- Java equals() and hashCode() Contract
- equals and Hashcode method in Java
- HashCode and Equals method in Java object – A pragmatic concept
- override the hashcode and equals method in java
- Java equals() and hashCode() Contract[转]
- Working with hashCode and equals methods in java
- JAVA 基础之 equals and HashCode
- java == equals hashcode 详解
- 比较Java中"hashCode" "equals" "==" "System.identityhashcode"
- Java equals compareTo()的区别
- @EqualsAndHashCode注解问题
- Java Program to print Prime numbers in Java - Example Tutorial and Code
- 哈希检索方面的论文、代码和数据集Learning to Hash Paper, Code and Dataset
- best strategies for implementation of equals() and hashcode() in your persistent classes
- How to support both ipv4 and ipv6 address for JAVA code.