title: Java dynamic return type?
body: <p>I have a container (List) of some elements of type T and want to filter it. So it contains only elements of a specific subtype U. Would it be possible to set a "dynamic" return type?</p>
  
  <p>example:</p>
  
  <pre><code>class SomeContainer&lt;T&gt; extends ArrayList&lt;T&gt;{
  
      public SomeContainer&lt;T&gt; subset(Class c){
          SomeContainer&lt;...here the type of c &gt; output = new SomeContainer&lt;.. also ..&gt;();
  
          //filter own elements and only add c-objects in the new list
  
          return output;
      }
  }
  </code></pre>
  
  <p>At the moment it returns a list of the generic type T and not of the c-Class-type (Subtype of T). Therefore I sometimes receive the following Compiler-Notice:</p>
  
  <pre><code>Note: SomeContainer.java uses unchecked or unsafe operations.
  Note: Recompile with -Xlint:unchecked for details.
  </code></pre>
  
  <p>Because I want to filter the list after objects of a subtype and trigger subtype-specific methods I would need a specific subtype list.</p>