0

When it is possible that if you interchange the lines of adding a and b, then

hashSet.size () == 2 instead of 3:
a = ;  
b = ;  
c = ;
Set <ThirdPartyType> hashSet = new ...;
hashSet.add (a); hashSet.add (b); hashSet.add (c);
Kalamarico
  • 5,466
  • 22
  • 53
  • 70
  • 7
    When you haven't implemented `hashCode`/`equals` correctly. – Oliver Charlesworth Jan 29 '18 at 11:05
  • Set doesn't allow duplicate values and the detection of duplication depends on `hashcode/equals` implementation. You must be adding three items but out of three two are same and hence the final size seems to be 2. – Bilbo Baggins Jan 29 '18 at 11:07
  • You should provide the `hashCode` and `equals` implementation of the `ThirdPartyType`. This is where the problem is. If you haven't implemented them, this is also where the problem is. – AxelH Jan 29 '18 at 11:50

0 Answers0