title: Unchecked conversion warning with generics
body: <p>I don't quite understand, why my code has to do a unchecked conversion and how I can fix that.</p>
  <p>I am implementing immutable objects with the builder pattern for which I implemented the &quot;Immutable&quot; interface with the inner interface &quot;Builder&quot;.</p>
  <p>Each immutable class implements the Immutable interface and implements a inner static class Builder, which implements the Builder interface.</p>
  <p>All this works fine.</p>
  <p>Now, I am implementing a bunch of very simple classes that don't really need a builder, but I still want to implement the Immutable interface, so the objects of those classes are instances of &quot;Immutable&quot;, but I don't want to implement empty builders without any functionality for each class. I'd rather have an abstract class in which to implement one simple builder for all the simple classes. The builder will just store the original object and return it through the build() method, so the Immutable interface is implemented completely</p>
  <p>The build() method of the builder has to return an object of the implementing class, though. So I added generics.</p>
  <pre><code>public interface Immutable {
      public interface Builder&lt;T&gt; {
          public T build();
      }
      public &lt;T&gt; Builder&lt;T&gt; builder();
  }
  
  
  public interface Interface extends Immutable {
  
      public interface BuilderInterface&lt;T&gt; extends Immutable.Builder&lt;T&gt; {
  
      }
  }
  
  
  public abstract class AbstractClass implements Interface {
  
      public static class AbstractBuilder&lt;T&gt; implements Interface.BuilderInterface&lt;T&gt; {
  
          private final T object;
  
          public AbstractBuilder(T object) {
  
              this.object = object;
          }
  
          @Override
          public T build() {
  
              return this.object;
          }
      }
  
      protected AbstractClass() {
  
          super();
      }
  }
  
  public class ConcreteClass extends AbstractClass {
  
      public ConcreteClass() {
  
      }
  
      @Override
      public AbstractBuilder&lt;ConcreteClass&gt; builder() {
  
          return new AbstractClass.AbstractBuilder&lt;ConcreteClass&gt;(this);
      }
  }
  </code></pre>
  <p>I was expecting the generic type T of the Immutable interface to take the type of the implementing class, but instead it seems to be Object, which leads to the following warning:</p>
  <p>Type safety: The return type <code>AbstractClass.AbstractBuilder&lt;ConcreteClass&gt;</code> for builder() from the type ConcreteClass needs unchecked conversion to conform to <code>Immutable.Builder&lt;Object&gt;</code> from the type Immutable</p>
  <p><strong>EDIT:</strong> The warning is given by the builder() method of ConcreteClass.</p>