title: Java Generics - Cannot convert from <? extends MyObject> to <MyObject>
body: <p>Why does the following code give a compile error?</p>
  
  <pre><code>public MyObject(Builder&lt;? extends MyObject&gt; builder) {
      // Type mismatch: cannot convert from MyObject.Builder&lt;capture#5-of ? extends MyObject&gt; to MyObject.Builder&lt;MyObject&gt;
      Builder&lt;MyObject&gt; myObjBuilder = builder;
  }
  </code></pre>
  
  <p>If the Builder type is a subclass of MyObject, then why can't you assign builder to just type MyObject? I need to do this because I am unable to use an object of type MyObject with the builder. Take a look at this code for example:</p>
  
  <pre><code>public MyObject(Builder&lt;? extends MyObject&gt; builder) {
      // The method getData(capture#8-of ? extends MyObject) in the type Builder&lt;capture#8-of ? extends MyObject&gt; is not applicable for the arguments (MyObject)
      this.data = builder.getData(this);
  }
  </code></pre>
  
  <p>I feel like this should be allowed. Or am I missing something here? Is there a way to do this without casting builder to <code>(Builder&lt;MyObject&gt;)</code> and having to use @SuppressWarnings ?</p>
  
  <p>Also note that I need Builder to be <code>&lt;? extends MyObject&gt;</code> because the MyObject and its Builder will be subclassed (as it is abstract).</p>
  
  <p>Thanks for your help!</p>