title: Calling a Factory without typecasting the return type
body: <p>This is the first time I am trying to make a factory.. please excuse me if I didn't use the pattern properly! </p>
  
  <p>So this is my Factory: </p>
  
  <pre><code>public class BuilderFactory { 
  
      public BuilderFactory(){        
      }
  
      public &lt;T extends Builder&gt; T getBuilderOf(Object clazz){
          if(clazz instanceof House){             
              return (T) new HouseBuilder();
          }
          return null;
      }
  }
  </code></pre>
  
  <p>it will return a builder (in this case HouseBuilder) which has a Builder interface.</p>
  
  <p>Builder: </p>
  
  <pre><code>public interface Builder&lt;T&gt; {
  
      T build();
  
  }
  </code></pre>
  
  <p>HouseBuilder:</p>
  
  <pre><code>public class HouseBuilder implements Builder&lt;House&gt; {
  
      private String street;
  
      public HouseBuilder() {
  
      }
      @Override
      public House build() {
          return new House(street);
      }
  
      @Override
      public HouseBuilder&lt;House&gt; withStreet(String street) {
          this.street = street;
          return this;
      }
  
  }
  </code></pre>
  
  <p>This is the place where I call it:</p>
  
  <pre><code>BuilderFactory builderFactory = new BuilderFactory();
  </code></pre>
  
  <p>Now it is possible to do:</p>
  
  <pre><code>builderFactory.getBuilderOf(House.class).build();
  </code></pre>
  
  <p>Since <code>build()</code> is in the <code>Builder</code> interface. But if I want to do:
   <code>builderFactory.getBuilderOf(House.class).withStreet("street");</code> </p>
  
  <p>I implicitily need to cast the builder like so:</p>
  
  <pre><code> (HouseBuilder)builderFactory.getBuilderOf(House.class).withStreet("street")
  </code></pre>
  
  <p>Or else the compiler will complain. </p>
  
  <p>I don't want to cast it, or instantiate my return value from the factory. Is there any option where I don't have to cast the result and could still use the <code>.withStreet()</code> method ? :)</p>
  
  <p>Thanks in advance.
  Davey</p>