« Return to the blog entry
I second Peter.
TreeSet is in Java1.3.
java.util.Sets just call the equal methods of the objects that are allready member of the Set.
They manage sorting by calling the compareTo method.
And BillingAdress has all it needs: compareTo AND equals method overriden.
Hm. Well there is something missing, that may generate nasty behaviour: You should ALLWAYS implement hashCode method whenever you override equals.
http://www.xyzws.com/javafaq/why-always-override-hashcode-if-overriding-equals/20
I allways use eclipse to implement this kind of stuff.
Source/Generate Hash Code and Equals,
Source/Generate ToString
Source/Generate Setters and Getters.
I second Peter.
TreeSet is in Java1.3.
java.util.Sets just call the equal methods of the objects that are allready member of the Set.
They manage sorting by calling the compareTo method.
And BillingAdress has all it needs: compareTo AND equals method overriden.
Hm. Well there is something missing, that may generate nasty behaviour: You should ALLWAYS implement hashCode method whenever you override equals.
http://www.xyzws.com/javafaq/why-always-override-hashcode-if-overriding-equals/20
I allways use eclipse to implement this kind of stuff.
Source/Generate Hash Code and Equals,
Source/Generate ToString
Source/Generate Setters and Getters.