[Java-gnome-developer] boolean equals(...)
Brought to you by:
afcowie
From: Jonas B. <jb...@ni...> - 2003-09-29 20:26:11
|
Hi! I found that there are an implementation of equals() in some classes that= =20 don't take an Object as a parameter, instead they take for example=20 TextIter or such. It is good practice to always override the equals(Object other) method in= =20 the Object class instead of creating a parallell equals() method. It can=20 be confusing and error-prone to have several equals() methods. Further, if one wants to use an object as a key for a HashMap, and one=20 overrides the equals(Object) method, it is also required of the object to= =20 implement the hashCode() method. Even if the javadoc documentation for=20 Object.hashCode() is maybe a bit cryptic, it gives more information on th= e=20 subject. When scanning the java-gnome sources, I found these equals() not taking a= n=20 Object parameter. ./java/org/gnu/gtk/event/ScaleEvent.java: public boolean equals(ScaleEvent event2){ ./java/org/gnu/gtk/TextIter.java: public boolean equals(TextIter other){ ./java/org/gnu/glib/Boxed.java: public boolean equals(Boxed other){ There were indeed also classes where both equals(Object) and hashCode()=20 were implemented. I'll see if I have some time to look into this, maybe I'll post a patch=20 later on if I manage. - xkr47 |