title: How to implement a builder class using Generics, not annotations?
body: <p>I want to write a generic <strong>builder class</strong> which wraps around any java class and providing setter functions of a specific style. I am not sure if this could be called "dynamically generated functions".</p>
  
  <p>When I have a beanish Pojo class i.e.</p>
  
  <pre><code>class Pojo {
      public void setValue(int value) {...}
      public void setName(String name) {...}
  }
  </code></pre>
  
  <p>My <code>Maker</code> class should be usable like this:</p>
  
  <pre><code>Pojo p = Builder&lt;Pojo&gt;.create(new Pojo())
               .setName("Funny")
               .setValue(123)
               .build();
  </code></pre>
  
  <p>As you can see, the work it does should be similar to</p>
  
  <pre><code>class PojoBuilder {
      private Pojo pojo;
      PojoBuilder(Pojo pojo) { this.pojo = pojo; }
      public static PojoMaker create(Pojo p) { return new PojoBuilder(p); }
      public PojoBuilder setName(String name) { pojo.setName(name); return this; }
      public PojoBuilder setValue(int val) { pojo.setValue(val); return this; }
      public Pojo make() { return pojo; }
  }
  </code></pre>
  
  <p>Only, I would like <code>Maker</code> to be generic. Obviously, the "setXyz"-Methods depend on the generic argument. How to do that?</p>
  
  <p>Of course, functionally equivalent but syntactically different approach is also fine.</p>
  
  <p>I'd like to do it without annotations: With annotations I gather I'd need a second javac-pass over my source code, generating the wrapper code. That seems to be what <em>Limbok</em> does or how some <em>JPA wrappers</em> work. But when I work with <em>Mockito</em> it seems that this pass is not necessary. So, How can I do it with <em>Generics</em>?</p>