I have my own class:
public class Coord {
int x;
int y;
public Coord(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int hashCode() {
int hash = (x + "-" + y).hashCode();
return hash;
}
}
With this Class I am testing the Hashset like this:
Set<Coord> set= new HashSet<Coord>();
set.add(new Coord(1,1));
set.add(new Coord(1,1));
set.add(new Coord(1,1));
When running this, I get a size of 3 of the hashset. I expected to have only 1. Can someone help me why ? I checked that the returned hashcode is always the same, but still the object is added to the set.