title: How to use `Collections.min()` on custom collection?
body: <p>I wrote a custom collection called <code>MySet&lt;T&gt;</code>, it's essentially a wrapper over <code>HashSet</code>:</p>
  
  <pre><code>import java.util.Collections;
  import java.util.HashSet;
  
  public class MySet &lt;T&gt; {
      private HashSet&lt;T&gt; set;
  
      public MySet() {
          this.set = new HashSet&lt;&gt;();
      }
  
      public MySet(T[] elements) {
          this.set = new HashSet&lt;&gt;();
          Collections.addAll(this.set, elements);
      }
      public HashSet&lt;T&gt; getSet() {
          return this.set;
      }
  }
  </code></pre>
  
  <p>It contains the methods that are relevant for sets like <code>union()</code>, <code>intersect()</code> etc.</p>
  
  <p>I also wrote a class called <code>Person</code> which represents basic details about a person and implements <code>Comparable</code> interface:</p>
  
  <pre><code>public class Person implements Comparable&lt;Person&gt; {
      private int id;
      private String name;
      private int age;
  
      public Person(int id, int age, String name) {
          this.id = id;
          this.age = age;
          this.name = name;
      }
  
      private boolean equals(Person p) {
          return this.age == p.age;
      }
  
      public int compareTo(Person p) {
          return this.age - p.age;
      }
  }
  </code></pre>
  
  <p>We compare <code>Person</code> objects based on <code>age</code> field. </p>
  
  <p>I <strong>need to write a third class</strong> that will only have the method which will receive a <code>MySet&lt;Person&gt;</code> object and will determine the minimum <code>Person</code>. Of course this can be done manually by using two loops to find the minimum age but the point is to use Java methods for generics, so I though using <code>Collections.min()</code> on <code>MySet&lt;Person&gt;</code>:</p>
  
  <pre><code>public class MinimumClass&lt;T&gt; {
      public T minElement(MySet&lt;T&gt; set) {
          Collections.min(set);
      }
  }
  </code></pre>
  
  <p>Which doesn't compile and gives an error: <code>no instance(s) of type variable(s) T exist so that MySet&lt;T&gt; conforms to Collection&lt;? extends T&gt;</code> which as far as I understand means that I have to implement <code>Collection</code> interface in <code>MySet</code>. </p>
  
  <p>Is there an easier way to write the method that will determine the minimum person using the fact that <code>Person</code> implements <code>Comparable</code> and <code>MySet</code> is a generic class?</p>