title: Java Generics- Can I create a list dynamically based on variable type
body: <p>Is there any way by which we can create specific instance of generic type at runtime?</p>
  
  <p>For example.</p>
  
  <pre><code>Cacheable instance = getCacheable(someInput);
  </code></pre>
  
  <p>getCacheble method will return me the instance of Cacheable. So it can be any class implementing Cacheable.for e.g. Customer,Product etc.Now I want to create a list of specific type returned by getCacheable as below.Is that possible? If yes how to do that?</p>
  
  <pre><code>List&lt;? extends Cacheable&gt; cacheList = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>I want to create <code>ArrayList&lt;Product&gt; or ArrayList&lt;Customer&gt;</code> based on the instance returned by getCacheable method.</p>