title: Abstract Class with enum Comparator: How to make it work?
body: <p>I would like to get the following thing to work.  My abstract class <code>T</code> extends <code>java.util.Comparator&lt;T&gt;</code> and should therefore allow me to use the <code>compareTo</code> method.  The problem is that <code>o1.t1.compareTo(o2.t1)</code> receives <code>The method compareTo(capture#2-of ?) is undefined for the type capture#1-of ?</code></p>
  
  <p>Could someone please explain the problem on a basic level and tell me how to potentially fix it?  Thanks a lot in advance.</p>
  
  <pre><code>public class TypeTypeComparator&lt;T extends java.util.Comparator&lt;T&gt;&gt; {
  
      public T t1;
      public T t2;
  
      public TypeTypeComparator() {
          this.t1 = null;
          this.t2 = null;
      }
  
      public TypeTypeComparator(T t1, T t2) {
          this.t1 = t1;
          this.t2 = t2;
      }
  
      public static enum Comparator implements java.util.Comparator&lt;TypeTypeComparator&lt;?&gt;&gt; {
          T1_SORT {
              public int compare(TypeTypeComparator&lt;?&gt; o1, TypeTypeComparator&lt;?&gt; o2) {
                  return o1.t1.compareTo(o2.t1);
              }},
          T2_SORT {
              public int compare(TypeTypeComparator&lt;?&gt; o1, TypeTypeComparator&lt;?&gt; o2) {
                  return o1.t2.compareTo(o2.t2);
              }};
  
          public static java.util.Comparator&lt;TypeTypeComparator&lt;?&gt;&gt; getComparator(final Comparator... options) {
              return new java.util.Comparator&lt;TypeTypeComparator&lt;?&gt;&gt;() {
                  public int compare(TypeTypeComparator&lt;?&gt; o1, TypeTypeComparator&lt;?&gt; o2) {
                      for ( Comparator option : options ) {
                          int result = option.compare(o1, o2);
                          if ( result != 0 )
                              return result;
                      }
                      return 0;
                  }
              };
          }
      }
  }
  </code></pre>