I have related question about hashCode() % capacity concept.
In many
scjp mocks and in Kathy Sierra & Bert Bates book there are questions like this:
class
Test {
int i;
Test(int i) {this.i = i;}
public boolean equals(Object o) {return ((Test)o).i == this.i}
}
HashSet s = new HashSet();
s.add(new Test(1));
s.add(new Test(1));
System.out.println(s.size()); // what will be the output?
Now the problem: authors say that 2 is correct answer -- "because hashCode() is not overriden, so two object will go to different buckets."
BUT! I think that even when each hashCode is unique, there is posiibility that hash1%capacity == hash2%capacity AND then the output is 1.
What do You think about it?