title: Generic factory with unknown implementation classes
body: <p>Let's assume two interfaces:</p>
  
  <pre><code>public interface FruitHandler&lt;T extends Fruit&gt;
  {
      setFruit(T fruit);
      T getFruit();
  }
  
  public interface Fruit
  {
  }
  </code></pre>
  
  <p>Now I want a factory to create <code>FruitHandlers</code> (e.g. <code>AppleHander</code>, <code>OrangeHandler</code>, ...), but the <code>FruitHandlerFactory</code> does not know neccessary about the implementing classes of both interfaces (like in <a href="https://stackoverflow.com/questions/4153767">java parameterized generic static factory</a>). The <code>FruitHandlerFactory</code> should work in this way (where <code>OrangeHandler</code> implements <code>FruitHandler</code> and <code>Orange</code> implements <code>Fruit</code>): </p>
  
  <pre><code>FruitHandlerFactory fhf = new FruitHandlerFactory&lt;OrangeHandler,Orange&gt;();
  OrangeHandler fh = fhf.create();
  Orange orange = (Orange)fh.getFruit();
  </code></pre>
  
  <p>This should be the factory:</p>
  
  <pre><code>public class FruitHandlerFactory&lt;A extends FruitHandler, B extends Fruit&gt;
  {
      public FruitHandler create()
      {
          FruitHandler&lt;Fruit&gt; fh = new A&lt;B&gt;();   //&lt;--- ERROR
          fh.setFruit(new B());
          return fh;
      }
  }
  </code></pre>
  
  <p>Where I get this error:</p>
  
  <pre><code>The type A is not generic; it cannot be parameterized with arguments &lt;B&gt;
  </code></pre>
  
  <p>BTW: Is it possible to make the <code>create()</code> method static?</p>