title: Java containers of generic types
body: <p>I am preparing for an exam and one of the codes we were given by professor is obscure to me:</p>
  
  <pre><code>public class Z {
  
      static java.util.LinkedList&lt;? extends Object&gt; a =
              new java.util.LinkedList&lt;String&gt;();
  
      public static void main(String[] args) {
          a.add(null); // 1
          a.add(new Object()); // 2
          a.add("new Object()"); // 3
          System.out.println(a); // 4
      }
  }
  </code></pre>
  
  <p>NetBeans gives me really strange compilation errors here:</p>
  
  
  
  <pre class="lang-none prettyprint-override"><code>no suitable method found for add(java.lang.Object)
  method java.util.LinkedList.add(capture#1 of ? extends java.lang.Object) is not applicable
  (actual argument java.lang.Object cannot be converted to capture#1 of ? extends java.lang.Object by method invocation conversion)
  
  no suitable method found for add(java.lang.String)
  method java.util.LinkedList.add(capture#2 of ? extends java.lang.Object) is not applicable
  (actual argument java.lang.String cannot be converted to capture#2 of ? extends java.lang.Object by method invocation conversion)
  </code></pre>
  
  <p>Could anyone please explain me these errors? I was pretty sure that it should be possible to add String objects to this list.</p>