title: How do define my own element class for use with Set
body: <p>I have the following code:</p>
  
  <pre><code>public class MyElement {
      String name;
      String type;
  
      MyElement(String name, String type) {
          this.name = name;
          this.type = type;
      }
  }
  
  public class Test {
  
      public static void main(String[] args) {
          Set&lt;MyElement&gt; set = new HashSet&lt;MyElement&gt;();
          set.add(new MyElement("foo", "bar"));
          set.add(new MyElement("foo", "bar"));
          set.add(new MyElement("foo", "bar"));
          System.out.println(set.size());
          System.out.println(set.contains(new MyElement("foo", "bar")));
      }
  }
  </code></pre>
  
  <p>which when executed comes back with:</p>
  
  <pre><code>3
  
  false
  </code></pre>
  
  <p>I would have expected the result to be 1 and true. Why are my elements not being recognised as being the same and how do I rectify this?
  Thanks,
  Wayne.</p>