再议Java5泛型

若类声明不适用泛型,而方法使用泛型,返回时应用下面的写法。

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;
    }

}

你可能感兴趣的:(java)