title: Abstract class for builder pattern
body: <p>I have existing model classes that always use builder pattern like this:</p>
  
  <pre><code>public class Model {
      public static class Builder {
          private boolean isValid;
          private List&lt;String&gt; errorMessagesOrNull;
  
          public Builder setIsValid(final boolean isValid) {
              this.isValid = isValid;
              return this;
          }
  
          public Builder setErrorMessages(final List&lt;String&gt; errorMessages) {
              this.errorMessagesOrNull = errorMessages;
              return this;
          }
  
          public List&lt;String&gt; getErrorMessages() {
              return this.errorMessagesOrNull == null ? new ArrayList&lt;&gt;() : this.errorMessagesOrNull;
          }
  
          public Model Build() {
              return new Model(this);
          }
      }
  
      private boolean isValid;
      private List&lt;String&gt; errorMessages;
  
      private Model(final Builder builder) {
          this.isValid = builder.isValid;
          this.errorMessages = builder.getErrorMessages();
      }
  
      public boolean getIsValid() {
          return isValid;
      }
  
      public List&lt;String&gt; getErrorMessages() {
          return errorMessages;
      }
  }
  </code></pre>
  
  <p>As you see, the model classes always have <code>isValid</code> and <code>errorMessages</code>. I want to write an abstract class to minimize the repeated logic for those model classes.</p>
  
  <p>So I came up like this abstract class:</p>
  
  <pre><code>public abstract class AbstractModel&lt;T extends AbstractModel&lt;T&gt;&gt; {
  
      public static abstract class Builder&lt;T&gt; {
          private boolean isValid;
          private List&lt;String&gt; errorMessagesOrNull;
  
          public Builder&lt;T&gt; setIsValid(final boolean isValid) {
              this.isValid = isValid;
              return this;
          }
  
          public Builder&lt;T&gt; setErrorMessages(final List&lt;String&gt; errorMessages) {
              this.errorMessagesOrNull = errorMessages;
              return this;
          }
  
          public List&lt;String&gt; getErrorMessages() {
              return this.errorMessagesOrNull == null ? new ArrayList&lt;&gt;() : this.errorMessagesOrNull;
          }
  
          public abstract T Build();
      }
  
      private boolean isValid;
      private List&lt;String&gt; errorMessages;
  
      private AbstractModel(final Builder&lt;T&gt; builder) {
          this.isValid = builder.isValid;
          this.errorMessages = builder.getErrorMessages();
      }
  
      public boolean getIsValid() {
          return isValid;
      }
  
      public List&lt;String&gt; getErrorMessages() {
          return errorMessages;
      }
  }
  </code></pre>
  
  <p>But it's not really working as I intended.  When I extends the abstract class:</p>
  
  <pre><code>public class Model extends AbstractModel&lt;Model&gt; {
      // Empty here since all fields are extended
  }
  </code></pre>
  
  <p>I cannot do something like:</p>
  
  <pre><code>Model model = new Model.Builder.setIsValid(true).Build();
  </code></pre>
  
  <p>I want the abstract class has <code>Builder</code> static class, so that I don't need to write the static class <code>Builder</code> every time.</p>
  
  <p>Please advise.</p>