title: Chain-Inheritance with the Building-Pattern
body: <p>i have a problem to get this pattern right with the java generics or maybe it wont work at all. Id like to have 2 abstract classes and a normal one. 
  Each childclass brings his own parameters to the classes. Form my perspective it looks like, i messed up with the generics, but i have no clue where.</p>
  
  <pre><code>public abstract class First {
  
  private final long id;
  
  First(Builder&lt;?&gt; builder) {
      this.id = builder.getId();
  }
  
  
  public static abstract class Builder&lt;T extends Builder&lt;T&gt;&gt; {
  
      @Getter long id;
  
      public abstract First build();
  
      public T setID(long id) {
          this.id = id;
          return (T)self();
      }
  
      protected abstract T self();
  }
  </code></pre>
  
  <p>second:</p>
  
  <pre><code>public abstract class Second extends First {
  
  Second(Builder&lt;?&gt; builder) { 
      super(builder);
  }
  
  
  public static abstract class Builder&lt;T extends Builder&lt;T&gt;&gt; extends First.Builder {
  
      public T print() {
          System.out.println("hi");
          return (T) self();
      }
  
  }
  }
  </code></pre>
  
  <p>and third:</p>
  
  <pre><code>public class Third extends Second {
  
  private Third(Builder builder) {
      super(builder);
  }
  
  public static class Builder&lt;T extends Builder&lt;T&gt;&gt; extends Second.Builder {
  
      public Third build() {
  
          return new Third(this);
      }
  
      @Override
      protected Builder self() {
          return this;
      }
  }
  
  }
  </code></pre>
  
  <p>my problem is, that i can call:</p>
  
  <pre><code>new Third.Builder()
              .print()
              .setID(1)
              .build();
  </code></pre>
  
  <p>but not:</p>
  
  <pre><code>new Third.Builder()
              .setID(1)
              .print()
              .build();
  </code></pre>
  
  <p>java gives me:</p>
  
  <pre><code>Error:(13, 17) java: cannot find symbol
  symbol:   method print()
  location: class blub.First.Builder
  </code></pre>