抽取dao!java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType问题出现原因

来源:互联网 发布:卖家农村淘宝签约好吗 编辑:程序博客网 时间:2024/05/22 01:37

//在这个方法继承一波。就okDictionaryDaoImpl dic = new DictionaryDao();//直接这样写报错BaseDao<Dictionary> base = new BaseDao<Dictionary>();Dictionary dictionary = dic.get("4028b8815fe7b236015fe7b23f6a0000");Dictionary dictionary2 = base.get("4028b8815fe7b236015fe7b23f6a0000");

java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

mmp!

附上basedao构造函数
private Class clazz;public BaseDao() {// 目的:得到实际类型参数// 得到当前运行对象Class clazz = this.getClass();// 得到当前对象父类的参数化类型,一般使用type子接口ParameterizedTypeType type = clazz.getGenericSuperclass();ParameterizedType ptype = (ParameterizedType) type;// 得到实际类型参数Type[] types = ptype.getActualTypeArguments();Class clazzParameter = (Class) types[0];this.clazz = clazzParameter;}


阅读全文
0 0