可以避免下面的演员表吗?
//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<Foo> {
}
public class DomainService<T extends Persistable>{
private Class<T> type;
public void findById(long id) {
domainDao.findById(id, type);
}
}
编辑:还是要投
public T findById(long id) {
return (T) fooDao.findById(id, type);
}