title: Java generics + Builder pattern
body: <p>How do I call <code>start()</code> below?</p>
  
  <pre><code>package com.example.test;
  
  class Bar {}
  
  public class Foo&lt;K&gt;
  {
      final private int count;
      final private K key;
  
      Foo(Builder&lt;K&gt; b)
      {
          this.count = b.count;
          this.key = b.key;
      }
  
      public static class Builder&lt;K2&gt;
      {
          int count;
          K2 key;
  
          private Builder() {}
          static public &lt;K3&gt; Builder&lt;K3&gt; start() { return new Builder&lt;K3&gt;(); }
          public Builder&lt;K2&gt; setCount(int count) { this.count = count; return this; }
          public Builder&lt;K2&gt; setKey(K2 key) { this.key = key; return this; }
          public Foo&lt;K2&gt; build() { return new Foo(this); }
      }
  
      public static void main(String[] args)
      {
          Bar bar = new Bar();
          Foo&lt;Bar&gt; foo1 = Foo.Builder.start().setCount(1).setKey(bar).build();
          // Type mismatch: cannot convert from Foo&lt;Object&gt; to Foo&lt;Bar&gt;
  
          Foo&lt;Bar&gt; foo2 = Foo.Builder&lt;Bar&gt;.start().setCount(1).setKey(bar).build();
          // Multiple markers at this line
          // - Bar cannot be resolved
          // - Foo.Builder cannot be resolved
          // - Syntax error on token ".", delete this token
          // - The method start() is undefined for the type Foo&lt;K&gt;
          // - Duplicate local variable fooType mismatch: cannot convert from Foo&lt;Object&gt; to Foo&lt;Bar&gt;
  
          Foo&lt;Bar&gt; foo3 = Foo&lt;Bar&gt;.Builder.start().setCount(1).setKey(bar).build();
          // Multiple markers at this line
          // - Foo cannot be resolved
          // - Syntax error on token ".", delete this token
          // - Bar cannot be resolved     
      }
  }
  </code></pre>