title: Java generics in ArrayList.toArray()
body: <p>Say you have an arraylist defined as follows:</p>
  
  <pre><code>ArrayList&lt;String&gt; someData = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>Later on in your code, because of generics you can say this:</p>
  
  <pre><code>String someLine = someData.get(0);
  </code></pre>
  
  <p>And the compiler knows outright that it will be getting a string. Yay generics! However, this will fail:</p>
  
  <pre><code>String[] arrayOfData = someData.toArray();
  </code></pre>
  
  <p><code>toArray()</code> will always return an array of Objects, not of the generic that was defined. Why does the <code>get(x)</code> method know what it is returning, but <code>toArray()</code> defaults to Objects?</p>