title: Struggling with generics and classes
body: <p>I'm always struggling with generics. I don't know why this makes my go crazy. I have an old problem I've got several times.</p>
  
  <pre><code>class Father {
      ...
  }
  
  class Child1 extends Father {
      ...
  }
  
  class Child2 extends Father {
      ...
  }
  
  public class TestClass {
      private static Class&lt;? extends Father&gt;[] myNiceClasses = new Class&lt;? extends Father&gt;[] {
          Child1.class,
          Child2.class
      }
  }
  </code></pre>
  
  <p>That does <strong>not</strong> work. The compiler complains like this:</p>
  
  <pre><code>Cannot create a generic array of Class&lt;? extends Father&gt;
  </code></pre>
  
  <p>If I change the (faulty) array line to</p>
  
  <pre><code>private static Class&lt;Father&gt;[] myNiceClasses = new Class&lt;Father&gt;[] {
  </code></pre>
  
  <p>the same error message occurs, but also this message is added:</p>
  
  <pre><code>Type mismatch: cannot convert from Class&lt;Child1&gt; to Class&lt;Father&gt;
  </code></pre>
  
  <p>The only working version is this line:</p>
  
  <pre><code>private static Class&lt;?&gt;[] myNiceClasses = new Class&lt;?&gt;[] {
  </code></pre>
  
  <p>This solution is not satisfying, because you cannot cast so easily.</p>
  
  <p>So my question is: How to solve this problem? Where's the knot in my brain?</p>