title: Invoking generic method with wildcards does not compile
body: <p>Could someone explain why the following code fragmnent does not compile? </p>
  
  <pre><code>public class Main {
  
      public static void main(String[] args) {
  
          Integer[] integers = {3, 5, 8};
          Set&lt;Integer&gt; s1 = new HashSet&lt;Integer&gt;(Arrays.asList(integers));
  
          Double[] doubles = {3.5, 5.5, 8.5};
          Set&lt;Double&gt; s2 = new HashSet&lt;Double&gt;(Arrays.asList(doubles));
  
          Set&lt;Number&gt; res1 = union(s1, s1);       // -&gt;it does not compile 
          Set&lt;Number&gt; res2 = union(s1, s2);       // -&gt;it does not compile
      }
  
      static &lt;E&gt; Set&lt;E&gt; union(Set&lt;? extends E&gt; s1, Set&lt;? extends E&gt; s2)
      {
          Set&lt;E&gt; result = new HashSet&lt;E&gt;(s1);
          result.addAll(s2);
          return result;
      }
  
  }
  </code></pre>
  
  <p>I have read the error messages:</p>
  
  <pre><code>Type mismatch: cannot convert from Set&lt;Integer&gt; to Set&lt;Number&gt;  Main.java   /TestingGenerics/src/com/al/testinggenerics line 17 Java Problem
  
  Type mismatch: cannot convert from Set&lt;Number&amp;Comparable&lt;?&gt;&gt; to Set&lt;Number&gt; Main.java   /TestingGenerics/src/com/al/testinggenerics line 18 Java Problem
  </code></pre>
  
  <p>What causes the problem as long as <code>Integer</code> and <code>Double</code> extend from <code>Number</code>?</p>