title: Java generics, wildcards, collections: compilation error
body: <p>Given the following class:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Collection;
  
  public class Main {
  
      private static class A {
      }
  
      private static class B&lt;T&gt; {
          private void thenReturn(T value) {
          }
      }
  
      private static &lt;T&gt; B&lt;T&gt; when(T methodCall) {
          return new B&lt;T&gt;();
      }
  
      private static Collection&lt;? extends A&gt; method() {
          return new ArrayList&lt;&gt;();
      }
  
      public static void main(String[] args) {
          Collection&lt;? extends A&gt; result = new ArrayList&lt;&gt;();
          // Does not compile.
          when(method()).thenReturn(result);
      }
  
  }
  </code></pre>
  
  <p>I get the compilation error <code>The method thenReturn(Collection&lt;capture#1-of ? extends Main.A&gt;) in the type Main.B&lt;Collection&lt;capture#1-of ? extends Main.A&gt;&gt; is not applicable for the arguments (Collection&lt;capture#3-of ? extends Main.A&gt;)</code></p>
  
  <p>What have I to change in the main method in order that it will compile? Is there a better solution than</p>
  
  <pre><code>    public static void main(String[] args) {
          Collection result = new ArrayList&lt;&gt;();
          when(method()).thenReturn(result);
      }
  </code></pre>