title: Does Inferred Covariance exist
body: <p>I am refactoring some code in to a builder pattern, and running in to an issue when sub-classing a builder for a child class.  </p>
  
  <p>When I have a builder subclass, and I try to chain a method in the parent, it is returning the parent builder, so my instance no longer has access to the child class methods.</p>
  
  <pre><code>public class App {
  
      public static void main(String[] args) {
          Parent p;
          p = new App().new ChildBuilder()
              .withName("Test")
              .withNickName("Test1")
              .build();// Doesn't Compile
          p = new App().new ChildBuilder()
              .withNickName("Test1")
              .withName("Test")
              .build();
  
      }
  
      class Parent {
          public Parent(ParentBuilder builder) {}
      }
  
      class Child extends Parent {
          public Child(ChildBuilder builder) { super(builder); }
      }
  
      class ParentBuilder {
          private String name;
          public ParentBuilder() {}
  
          public Parent build() { return new Parent(this); }
  
          public ParentBuilder withName(String name) { 
              this.name = name; 
              return this; 
          }
      }
  
      class ChildBuilder extends ParentBuilder {
          private String nickName;
          public ChildBuilder withNickName(String nickName) { 
              this.nickName = nickName; 
              return this; 
          }
      }
  }  
  </code></pre>
  
  <p>The second line in the main method won't compile because <code>withName("Test")</code> is on the ParentBuilder class and returns a ParentBuilder.  Reordering the chains to call all the ChildBuilder methods first fixes the problem, but that sounds like a terrible experience for the people using my api (myself included).<br>
  If I add an override in the child I can make it work through covariance:</p>
  
  <pre><code>        @Override
          public ChildBuilder withName(String name) { 
              super.withName(name); 
              return this; 
          }
  </code></pre>
  
  <p>But this is a lot of boilerplate code that I would rather not maintain (each parent builder could have a handful of subclasses, so I would need to rewrite these methods in each subclass for each method in the parent class).  </p>
  
  <p>Is there a way to do what I am trying to do without the overrides?  Can java "infer" the covariant methods in the children?</p>
  
  <p>I am also worried that this issue is indicative that I am designing the builders incorrectly.</p>