Perhaps I should have tried it before replying ;-). That hasn't fixed my problem, unfortunately. If I call prop1.equals(prop2) exlicitly, it calls this method, but when I call the retainsAll() method on HashSet it isn't calling this method.

Fritz

On 5/10/06, Fritz Meissner <[EMAIL PROTECTED]> wrote:
Thanks. Why is compareTo() not the right method?

Fritz


On 5/10/06, klutz <[EMAIL PROTECTED] > wrote:

You need to override the equals method on Proposition : ( Collections
use the equals method to check for equality )

You have to take care when you override the equals method that you
implement the contract of the equals method properly... ( Check the
JavaDoc on java.lang.Object )...

If you don't... you get some VERY funky behaviour on collections... :)

.... this SHOULD implement the contract of equals() correctly... just
give it another pair of eyballs...

public boolean equals( Object o ) {
   if ( ! o instanceof Proposition ) {
     return false;
   }
   if ( o == null ) {
     return false;
   }
   return ObjectUtils.equals(getName(),other.getName());
}

ObjectUtils is part of commons-lang and takes care of all the
additional null checking...

The lazy developers friend.. :):):)

Cheers,
Renier




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CTJUG Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za
-~----------~----~----~----~------~----~------~--~---

Reply via email to