若类声明不适用泛型,而方法使用泛型,返回时应用下面的写法。
public class Test{
public <T> T getById(Class<T> clazz, String id) {
Object t=null;
try {
t=this.userDao.find(clazz, id);
} catch(JccpException e) {
e.printStackTrace();
}
return (T)t;
}
}