I want to create a map which has a certain class as a key. The problem I ran into is that since this class contains pointers, this address is used when hashing if I use a HashMap (See my code below). How can I get it to compare the actual values rather than the address, or is there some other container that I can use that'll achieve the same result?
import java.util.*;
public class Main {
public static void main(String args[]) {
class Foo {
public Foo(String a) {s = a;}
public String s;
}
HashMap<Foo,Integer> a = new HashMap<Foo,Integer>();
a.put(new Foo("test"), 1);
System.out.println(a.get(new Foo("test")));
}
}
This outputs null