title: Comparator two compare Methods with Reflection
body: <p>I was trying to fix a Problem with an unknown Comparator (no Source access).
  So I've wrote some Reflection Code to see what Types that Comparator accepts.</p>
  
  <p>Surprisingly, Reflection tells me, there are two compare-Methods, one with the real type and one with Object:</p>
  
  <pre><code>Comparator&lt;Integer&gt; comp = new Comparator&lt;Integer&gt;()
  {
  
      @Override
      public int compare(Integer o1, Integer o2)
      {
          return 0;
      }
  };
  
  Method[] methods = comp.getClass().getMethods();
  for (Method method : methods)
  {
      if(method.getName().equals("compare")){
          System.out.println(method);
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>public int de.hinneLinks.stackoverflow.MyClass$1.compare(java.lang.Integer,java.lang.Integer)
  public int de.hinneLinks.stackoverflow.MyClass$1.compare(java.lang.Object,java.lang.Object)
  </code></pre>
  
  <p><strong>Where is that second <code>compare</code> Method coming from?</strong> </p>
  
  <p>But its not usable, why?:</p>
  
  <pre><code>comp.compare(1, 2); //Compiles
  comp.compare((Object)1,(Object)2); //Does not Compile
  </code></pre>
  
  <p>I can however call those Methods with Reflection, if i call both Methods with <code>new Object()</code>, i'll get two different Exceptions:</p>
  
  <pre><code>compare(java.lang.Object,java.lang.Object)
  java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.Integer
  
  compare(java.lang.Integer,java.lang.Integer)
  java.lang.IllegalArgumentException: argument type mismatch
  </code></pre>
  
  <p>If define my Comparator with Object, then there is only one Method.</p>