Is is possible to have a collection of generic collections?
<p>I'm writing some code that needs to process an arbitrary number of lists of doubles. However, although I can declare function parameters of type <code>List&lt;List&lt;Double&gt;&gt;</code> I'm having trouble creating actual instances since I need to create instances of a concrete class such as <code>ArrayList</code></p>

<p>I've tried</p>

<pre><code>List&lt;? extends List&lt;Double&gt;&gt; inputs = new ArrayList&lt;List&lt;Double&gt;&gt;();
inputs.add(new ArrayList&lt;Double&gt;());
</code></pre>

<p>and</p>

<pre><code>List&lt;? extends List&lt;? extends Double&gt;&gt; inputs = new ArrayList&lt;List&lt;Double&gt;&gt;();
inputs.add(new ArrayList&lt;Double&gt;());
</code></pre>

<p>but in both cases I get a compile error on the call to <code>add()</code> saying that the method is not applicable for arguments of type <code>ArrayList&lt;Double&gt;</code></p>

<p>This works</p>

<pre><code>List&lt;List&lt;Double&gt;&gt; inputs = new ArrayList&lt;List&lt;Double&gt;&gt;();
inputs.add((List&lt;Double&gt;) new ArrayList&lt;Double&gt;());
</code></pre>

<p>but it's kind of ugly to have to use casts in this way. Is there a better approach?</p>
