title: Avoid cast in java (Generics)
body: <p>Is the a way the cast below can be avoided? </p>
  
  <pre><code>//Is there a way this can be implemented so the cast is not necessary? 
  FooService fooService = new FooService();
  Foo f = (Foo)fooService.findById(id);
  
  public class FooService extends DomainServiceImpl&lt;Foo&gt; {
  }
  
  public class DomainService&lt;T extends Persistable&gt;{
  
     private Class&lt;T&gt; type;
  
     public void findById(long id) {
        domainDao.findById(id, type);
     }
  }
  </code></pre>
  
  <p>edit: Still have to cast</p>
  
  <pre><code>public T findById(long id) {
      return (T) fooDao.findById(id, type);
  }
  </code></pre>