title: Using an object to instantiate a collection
body: <p>I would like to do the following (which doesn't work, it is just to explain the concept). Any idea how to do it?</p>
  
  <pre><code>Class type;
  if (/* something */)
    type = String.class;
  else
    type = Boolean.class;
  
  return new ArrayList&lt;type&gt;();
  </code></pre>
  
  <p><code>ArrayList&lt;type&gt;</code> doesn't work. I tried with <code>type.getClass()</code>, doesn't work either.</p>