title: Creating an array of generic collections
body: <p>Actually, the question should be</p>
  
  <pre><code>Creating an array of generic anything.
  </code></pre>
  
  <p>Why can't the compiler take care of it?</p>
  
  <p>The following would be flagged as an error - cannot create generic array.</p>
  
  <pre><code>List&lt;MyDTO&gt;[] dtoLists = {new ArrayList&lt;MyDTO&gt;(), anExistingDtoList};
  </code></pre>
  
  <p>To overcome that, I need to</p>
  
  <pre><code>List&lt;MyDTO&gt;[] dtoLists = (List&lt;MyDTO&gt;[])Array.newInstance(ArrayList.class, 2);
  dtoLists[0] = new ArrayList&lt;MyDTO&gt;();
  dtoLists[1] = anExistingDtoList;
  </code></pre>
  
  <p>So, why can't the compiler convert the first case into the second case?</p>
  
  <p>I do realise that generics are compile-time determinate and not run-time determinate, while arrays are run-time determinate and therefore need a determinate type in order to create an array.</p>
  
  <p>What are the technological/logical barriers compiler designers would encounter that would prevent them being able to implement this?</p>
  
  <p>Is the issue purely philosophical, concerning language orthogonality? If so, how would such a behaviour violate language orthogonality?</p>
  
  <p>Is it a question of complexity? Explain the complexity.</p>
  
  <p>I am hoping answers to my question would give me better insight into java compiler behaviour when it concerns generics.</p>
  
  <p><em>Side note:
  c'mon stop being trigger happy. The answers <a href="https://stackoverflow.com/questions/7810074/array-of-generic-list">Array of Generic List</a>
  do not answer my question. Why can't compilers spontaneously perform the conversion?</em></p>