title: Specifying a generic type in java from Class object
body: <p>Why this is wrong:</p>
  
  <pre><code>    Class&lt;? extends Number&gt; type = Integer.class;
      ArrayList&lt;type&gt; = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>?</p>
  
  <p>Is there no way to instantiate a class of a specific type given a class object?</p>
  
  <hr>
  
  <p>Obviously I would never do that directly, that is just an example to show what is needed. In the actual code I need I don't know the name of the type. For example</p>
  
  <pre><code>    public void createAList(Class&lt;? extends Number&gt; type)  
  {
      ArrayList&lt;type&gt; toReturn = new ArrayList&lt;&gt;();
      return toReturn;
  }
  </code></pre>