The aplication will say if the user has guessed the two combination of colors that he has introduced.
I'm using a HashMap for saving an "TwoColors" object and a boolean. The TwoColors class is the next:
public class TwoColors{
public MyColor color1;
public MyColor color2;
public TwoColors(MyColor color1, MyColor color2){
this.color1 = color1;
this.color2 = color2;
}
@Override
public boolean equals(Object obj) {
TwoColors o = (TwoColors) obj;
return color1 == o.color1 && color2 == o.color2;
}
}
And MyColor is an enum
public enum MyColor{
RED,BLUE,YELLOW,BROWN;
}
I test to put a TwoColor object key and print its value
public static void main(String[] args){
HashMap<TwoColors, Boolean> hash = new HashMap<TwoColors, Boolean>();
hash.put(new TwoColors(MyColor.RED,MyColor.BLUE),new Boolean(true));
System.out.println(hash.get(new TwoColors(MyColor.RED,MyColor.BLUE)));
}
The above code outputs null
although I have overriden TwoColors' equals method. Any idea what am I missing here?