Here's my code:
class Main{
static HashMap<Wrapper, Thing> map = new HashMap<Wrapper, Thing>();
public static void main(String[] args){
map.put(new Wrapper(1,2,3), new Thing(...));
System.out.println(map.containsKey(new Wrapper(1, 2, 3)); // prints 'false'
}
private static class Wrapper{
int[] array;
public Wrapper(int... array){
this.array = array;
}
public boolean equals(Object object){
if(!(o instanceof Wrapper)) return false;
return Arrays.equals(this.intervals, ((Wrapper) o).intervals);
}
}
}
Why does map.containsKey(new Wrapper(1, 2, 3)
return false
?