title: Java generics: wildcard<?> vs type parameter<E>?
body: <p>I am refreshing my knowledge on Java generics. So I turned to the excellent tutorial from Oracle ... and started to put together a presentation for my coworkers. I came across the section on wildcards in the <a href="http://docs.oracle.com/javase/tutorial/java/generics/unboundedWildcards.html" rel="noreferrer">tutorial</a> that says:</p>
  
  <blockquote>
    <p>Consider the following method, printList:</p>
  
  <pre><code>public static void printList(List&lt;Object&gt; list) {
  ...
  </code></pre>
    
    <p>The goal of printList is to print a list of any type, but it fails to achieve that goal — it prints only a list of Object instances; it cannot print <code>List&lt;Integer&gt;</code>, <code>List&lt;String&gt;</code>, <code>List&lt;Double&gt;</code>, and so on, because they are not subtypes of <code>List&lt;Object&gt;</code>. To write a generic printList method, use <code>List&lt;?&gt;</code>:</p>
  
  <pre><code>public static void printList(List&lt;?&gt; list) {
  </code></pre>
  </blockquote>
  
  <p>I understand that <code>List&lt;Object&gt;</code> will not work; but I changed the code to</p>
  
  <pre><code>static &lt;E&gt; void printObjects(List&lt;E&gt; list) {
      for (E e : list) {
          System.out.println(e.toString());
      }
  }
  ...
      List&lt;Object&gt; objects = Arrays.&lt;Object&gt;asList("1", "two");
      printObjects(objects);
      List&lt;Integer&gt; integers = Arrays.asList(3, 4);
      printObjects(integers);
  </code></pre>
  
  <p>And guess what; using <code>List&lt;E&gt;</code> I can print different types of Lists without any problem. </p>
  
  <p>Long story short: at least the tutorial indicates that one <strong>needs</strong> the wildcard to solve this problem; but as shown, it can be solved this way too. So, what am I missing?!</p>
  
  <p>(side note: tested with Java7; so maybe this was a problem with Java5, Java6; but on the other hand, Oracle seems to do a good job regarding updates of their tutorials)</p>