码上敲享录 > java入门知识分享 > ReflectionUtils.getSuperClassGenricType用法

ReflectionUtils.getSuperClassGenricType用法

上一章章节目录下一章 2018-04-14已有3990人阅读 评论(0)

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

本文地址:http://www.yayihouse.com/yayishuwu/chapter/1178

向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
1

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交