title: Why does java.lang.Class's getInterfaces() method return Class<?>[] and not Class<? super T>[]?
body: <p>(To clear up the question, 'T' refers to a type parameter declared in Class)</p>
  
  <p>Just as an example, please review the following application:</p>
  
  <pre><code>public class TestClass {
  
      interface InterfaceA{}
  
      interface InterfaceB{}
  
      interface InterfaceC{}
  
      class ClassA implements InterfaceA, InterfaceB,  InterfaceC{}
  
  
      public static void main(String[] args){    
  
          Class&lt;? super ClassA&gt; superClass1 = ClassA.class;
          Class&lt;? super ClassA&gt; superclass2 = InterfaceA.class;
          Class&lt;? super ClassA&gt; superclass3 = InterfaceB.class;
          Class&lt;? super ClassA&gt; superclass4 = InterfaceC.class;
  
          for(Class&lt;?&gt; clazz : ClassA.class.getInterfaces()){
              System.out.println(clazz.getName());
          }   
      }
  }
  </code></pre>
  
  <p>The output is what one would expect:</p>
  
  <pre><code>TestClass$InterfaceA
  TestClass$InterfaceB
  TestClass$InterfaceC
  </code></pre>
  
  <p>So, based on this example above, we can see that the compiler recognizes that InterfaceA <strong><em>does</em></strong> meet the bounds of the wildcard , as do all of the other interfaces.</p>
  
  <p>Intuitively, I would expect the following to be safe, but it is not:</p>
  
  <pre><code>Class&lt;? super ClassA&gt;[] interfaces = ClassA.class.getInterfaces();
  </code></pre>
  
  <p>The compiler gives a warning, because the signature says that it returns Class; however, the javadoc for Class states the following:</p>
  
  <blockquote>
    <p>If this object represents a class, the return value is an array
    containing objects representing all interfaces implemented by the
    class.</p>
  </blockquote>
  
  <p>'This object' refers in our case to <code>ClassA</code>.  Based on this statement, if we call:</p>
  
  <pre><code>ClassA.class.getInterfaces()
  </code></pre>
  
  <p>then we know, logically, that every <code>Class&lt;?&gt;</code> in the returned array will contain a reference to a super type of <code>ClassA</code>.</p>
  
  <p>As an additional point of reference:</p>
  
  <p>From the Java Language Reference, Third Edition:</p>
  
  <blockquote>
    <p>A class necessarily implements all the interfaces that its direct
    superclasses and direct superinterfaces do. This (multiple) interface
    inheritance allows objects to support (multiple) common behaviors
    without sharing any implementation.</p>
  </blockquote>
  
  <p>Reading this and other parts of the specification, I would think that any class or interface implemented or exteneded by a class <code>T</code> would fall into the bounds <code>&lt;? super T&gt;</code>.</p>
  
  <p>EDITED:</p>
  
  <p>It has been suggested that there is no concrete reason for my question.  I will provide an example:</p>
  
  <pre><code>1    import java.util.Map;
  2    import java.util.HashMap;
  3    
  4    public class MapWrapper&lt;T&gt; {
  5        private final Map&lt;Class&lt;?&gt;, OtherClass&lt;T,?&gt;&gt; map = new HashMap &lt;Class&lt;?&gt;, OtherClass&lt;T,?&gt;&gt;();
  6    
  7        public &lt;W&gt; void addToMap(Class&lt;W&gt; type, OtherClass&lt;T,? super W&gt; otherClass){
  8            map.put(type, otherClass);
  9        }
  10    
  11        public &lt;W&gt; OtherClass&lt;T,? super W&gt; getOtherClassForAnyInterface(Class&lt;W&gt; type){
  12            if(type.getInterfaces()!=null){
  13                for(Class&lt;?&gt; interfaceType : type.getInterfaces()){
  14                    // Here, a cast is necessary.  It throws a compiler warning for unchecked operations (rightfully so)
  15                    OtherClass&lt;T,? super W&gt; otherClass = (OtherClass&lt;T,? super W&gt;)getOtherClassForInterface(interfaceType);
  16                    if(null!=otherClass){
  17                        return otherClass;
  18                    }
  19                }
  20            }
  21            return null;
  22        }
  23    
  24        
  25        public class OtherClass&lt;T,V&gt; {}
  26    
  27    }
  </code></pre>
  
  <p>The problem is at line 15.  You have to cast to <code>&lt;? super W&gt;</code> to get the correct type.  The compiler warning can be suppressed, but is it justified? Is there some scenario where this cast is not true?</p>