Sunday 15 March 2015

collections - Why does my class not work properly in a Java HashSet? -


I am working on a project that involves using a class of HashSet That's what I'll name the test . I have defined the declaration like HashSet :

  hashaseet & lt; Test & gt; T = new hashset & lt; Test & gt; (); T.add (new test ("asdf", 1)); T.add (new test ("Hello", 2)); T.add (new test ("Hello", 3));  

I tried to use

  t.contains (new test ("asdf", 1));  

But it returns false However, when I type HashSet < Character & gt; then it works fine I tried to override the previous equal declaration, but it does not work, I try to leave equal alone But I still got the false I want to know what I am doing wrong?

Also, I have not edited the hash function, I only test. Axel (object o) has changed. This is a simple project and the Java documentation says that it uses o.equals (this), I thought I would not have to do this.

You may also need to load the hash code () method.


No comments:

Post a Comment