I am using Processing language (derived from Java PApplet) version 3.01
Here is my code...
Pig a = new Pig(1);
Pig b = new Pig(1);
HashMap<Pig, String> m = new HashMap<Pig, String>();
m.put(a,"foo");
String c = m.get(b);
println(c);
class Pig {
int a;
Pig(int x) { a=x;}
boolean equals(Pig b) { return b.a==a;}
int hashCode() { return a;}
}
As you can see I am using Pig for key, I defined the equals and hashCode. I expect output "foo", however, I get output null.
Any idea what is going on here? Why doesn't this work?