title: Java generics and varargs
body: <p>I'd like to implement a function with both generics and varargs.</p>
  
  <pre><code>public class Question {
      public static &lt;A&gt; void doNastyThingsToClasses(Class&lt;A&gt; parent, Class&lt;? extends A&gt;... classes) {
          /*** something here ***/
      }
      public static class NotQuestion {
      }
      public static class SomeQuestion extends Question {
      }
      public static void main(String[] args) {
          doNastyThingsToClasses(Object.class, Question.class, SomeQuestion.class); // OK
          doNastyThingsToClasses(Question.class, SomeQuestion.class); // OK
          doNastyThingsToClasses(Question.class, Object.class, SomeQuestion.class); // compilation failure
      }
  }
  </code></pre>
  
  <p>The intention here is to assert that all parameters passed to this function are Class objects extending the Class given as the first parameter. So the two first lines of main method would compile and the 3rd one generates an error.</p>
  
  <p><I>My question is:</I> Why I get "Type safety : A generic array of Class is created for a varargs parameter" message for the first two lines?</p>
  
  <p>Am I missing something here?</p>
  
  <p><I><B>Additional question:</B></I> how to redesign it to prevent this warning from being shown on every line calling "doNastyThingsToClasses" function? I can change it to "doNastyThingsToClasses(Class&lt;A> parent, Class&lt;?>... classes)" and get rid of the warnings but this also removes the compilation-time type checking --- not so good if I wanted to assure the right use of this function. Any better solution?</p>