title: Java Generics Capture List<?>
body: <p>I was looking at the <a href="http://docs.oracle.com/javase/tutorial/java/generics/capture.html" rel="nofollow">Java Generics documentation</a> and found this piece of code,</p>
  
  <pre><code>public class WildcardError {
  
  void foo(List&lt;?&gt; l) {
      //This give a compile time error
      l.set(0,l.get(0));
  }
  }
  </code></pre>
  
  <p>I can understand that we are fetching an element from a <code>List&lt;?&gt;</code> and trying to set it to another <code>List&lt;?&gt;</code>. So the compiler gives an error. My question is it makes sense when the 2 lists are different i.e. <code>l.set(0, m.get(0))</code> here lists <code>l</code> and <code>m</code> are different. But in the above example, <code>l</code> and <code>l</code> are the same lists. Why isn't the compiler smart enough to see that? Is it hard to implement it?</p>
  
  <p><strong>Edit</strong>:
  I am aware that I can fix it by a helper method or by using <code>T</code> instead of a <code>?</code>. Just wondering why compiler doesn't do it for me.</p>