title: Combining Raw Types and Generic Methods
body: <p>Here's a question, this first code listing compiles just fine (JDK 1.6 | JDK 1.7):</p>
  
  <pre><code>ArrayList&lt;String&gt; a = new ArrayList&lt;String&gt;();
  String[] s = a.toArray(new String[0]);
  </code></pre>
  
  <p>However, if I declare the <code>List</code> reference as a raw type:</p>
  
  <pre><code>ArrayList a = new ArrayList();
  String[] s = a.toArray(new String[0]);
  </code></pre>
  
  <p>I get a compiler error saying the <code>String[]</code> is required but <code>Object[]</code> was found. </p>
  
  <p>This means my compiler is interpreting the generic method as returning <code>Object[]</code> despite of receiving a <code>String[]</code> as its argument.</p>
  
  <p>I doubled-checked the <code>toArray(myArray)</code> method signature:</p>
  
  <pre><code>&lt;T&gt; T[] toArray(T[] a);
  </code></pre>
  
  <p>Therefore it is a parameterized method whose type parameter <code>&lt;T&gt;</code> has no relation whatsoever with that of the List (i.e. <code>&lt;E&gt;</code>). </p>
  
  <p>I have no idea how using a raw type here affects the evaluation of parameterized methods using independent type parameters. </p>
  
  <ul>
  <li>Does anyone has any idea why this code does not compile? </li>
  <li>Does anybody knows any reference where this behavior is documented?</li>
  </ul>