This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Originally posted by Deepak Bajoria: What is the effect of overrding equals method on Set.
I mean, Can a set have objects which are different but are "meaningfully" equal. The equals() has been correctly overridden i n the custom class to test the "meaningful equality"
Thanks in advance
Nope, javadoc says...
boolean add(E e)
Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element e to this set if the set contains no element e2 such that (e==null ? e2==null : e.equals(e2)). If this set already contains the element, the call leaves the set unchanged and returns false.
Joined: Mar 07, 2008
But see here this code:
This produces the output: Size:1 Size:2
Two objects here obj and obj1 are meaningfully equal, But they have been added to the set. [ July 23, 2008: Message edited by: Deepak Bajoria ]