I am working on a project that involves me using a HashSet
of a class I made, which I will name Test
. I defined the stated HashSet
like so:
HashSet<Test> t = new HashSet<Test>();
t.add(new Test("asdf", 1));
t.add(new Test("hello", 2));
t.add(new Test("hello", 3));
I tried using
t.contains(new Test("asdf", 1));
but it returns false
. However, when I use a HashSet<Character>
it seems to work fine. I tried overriding the previous equals
declaration, but it didn't work. I tried leaving equals
alone, but i still got false
. I need to know what i am doing wrong?
also, i did not edit the hash function, i only changed Test.equals(Object o). It's a simple project and since the java documentation states that it uses o.equals(this), i thought i would not have to.