ReflectionUtils.getSuperClassGenricType用法?
解决方法:
以例子来解说
1.泛型类
import org.springside.modules.utils.reflection.ReflectionUtils;
@Repository("baseDao")
public class BaseDao<T, ID extends Serializable> implements IBaseDao<T, ID>{
protected Logger logger = LoggerFactory.getLogger(getClass());
protected Class<T> entityClass;
protected Class<ID> idClass;
public BaseDao() {
this.entityClass = ReflectionUtils.getSuperClassGenricType(getClass());
}
}
2。继承BaseDao类,T=SysParams,ID=Integer
@Repository
public class SysParamsDao extends BaseDao<SysParams, Integer> {
//省略代码
}
启动tomcat时,会执行BaseDao的构造方法BaseDao()
getClass()的值为SysParamsDao
ReflectionUtils.getSuperClassGenricType(getClass())的值为SysParams
ReflectionUtils.getSuperClassGenricType(getClass(),0)的值为SysParams
ReflectionUtils.getSuperClassGenricType(getClass(),1)的值为Integer