title: Java Generic List<>
body: <p>I am trying to do something like this:</p>
  
  <p><em>1. Approach</em></p>
  
  <pre><code>Type ty = entityType.getEntityClass(); // could be e.g. String.class  
  List&lt;ty&gt; list;
  </code></pre>
  
  <p><em>2. Approach</em></p>
  
  <pre><code>Class cl = entityType.getEntityClass(); // could be e.g. String.class
  List&lt;cl&gt; list;
  </code></pre>
  
  <p>However, compiler simply says "no".</p>
  
  <p>Is there any way to set the generic type <code>&lt;T&gt;</code> of e.g. a java.util.List dynamic only by having e.g. <code>String.class</code> or <code>foo.getClass()</code>?</p>
  
  <p>...</p>
  
  <p>What I am actually trying to do is initializing a List by a given parameter of type <code>EntityTypeEnum</code> or it's <code>Class</code> property value.</p>
  
  <pre><code>public enum EntityTypeEnum {
      ARTICLE(Article.class),
      ORDER(OrderHeader.class),
      CUSTOMER(Customer.class),
      CUSTOMER_SESSION(CustomerSession.class);
  
      private final Class entityClass;
  
      private EntityTypeEnum(final Class entityClass) {
          this.entityClass = entityClass;
      }
  
      public Class getEntityClass() {
          return entityClass;
      }
  }
  </code></pre>
  
  <p>Constructive criticism is welcome.
  Thank you!</p>
  
  <blockquote>
    <p>Add: (as a response of Andy's comment)</p>
  </blockquote>
  
  <pre><code>Class cl = String.class;
  List&lt;cl&gt; list;
  </code></pre>
  
  <p>..is not working either!</p>
  
  <pre><code>List&lt;String&gt; list;
  </code></pre>
  
  <p>..works, of course.</p>
  
  <p>So what is this difference between <code>String</code> and <code>String.class</code>?</p>
  
  <p>Or is there a way to set the value like: </p>
  
  <pre><code>public enum EntityTypeEnum {
      ARTICLE(Article)
  ..
  </code></pre>