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.
posted 10 years ago
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 ]