java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType的解决方案之一
Constructor threw exception; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
/*** 获取泛型T的class类对象* @return 泛型T的class类对象*/public Class<T> getTClass() {return (Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];}
改成使用instanceof
关键字进行强转判断
/*** 获取泛型T的class类对象,强转判断* @return 泛型T的class类对象*/public Class<T> getTClass() {Type type = this.getClass().getGenericSuperclass();if(type instanceof ParameterizedType){ParameterizedType parameterizedType = (ParameterizedType) type;Type[] types = parameterizedType.getActualTypeArguments();return (Class<T>) types[0];}}
java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType的解决方案之一相关推荐
- java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer 1.改sql select ...
- ArrayMap java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[]
错误堆栈: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[]at android. ...
- 在拦截器中获取请求参数,[Ljava.lang.String; cannot be cast to java.lang.String报错
Map<String,Object> parametersmap=invocation.getInvocationContext().getParameters();//获取请求参数 ...
- Java报错:java.math.BigDecimal cannot be cast to java.lang.String
从数据库取数字,转为string,报错: java.math.BigDecimal cannot be cast to java.lang.String 错误代码 Integer.parseInt(( ...
- “无效数字” ;java.lang.Integer cannot be cast to java.lang.String
今天页面上突然查询不出数据,大致的sql语句是 select xx ,xxx from table a where a.lrmb in ( 6101060033, 61010503300, 61016 ...
- java.lang.Long cannot be cast to java.lang.Integer解决办法
情景: mybatis连接oracle 报错: 测试增的时候,报错 Java.lang.Long cannot be cast to java.lang.Integer:删改没有报错. 排查过程: ...
- [记录]java.math.biginteger cannot be cast to java.lang.long
可以直接使用BigInteger类型进行接收, BigInteger id = (BigInteger)QueryRunner(conn,"SELECT LAST_INSERT_ID&quo ...
- java string转long报错_java.lang.Integer cannot be cast to java.lang.Long解决办法
你好我是辰兮,本次是项目遇到的java.lang.Integer cannot be cast to java.lang.Long异常以及相对应的解决方案. 文章目录 一.实战问题 用postman测 ...
- java.math.BigDecimal cannot be cast to java.lang.Integer
问题描述:利用sql语句从数据库里面取出数据后,对取出的数据进行数据转换时,出现了java.math.BigDecimal cannot be cast to java.lang.Integer错误, ...
- mysql连接报java.math.BigInteger cannot be cast to java.lang.Long异常
mysql连接报java.math.BigInteger cannot be cast to java.lang.Long异常 参考文章: (1)mysql连接报java.math.BigIntege ...
最新文章
- 如何在敏捷框架下做好工作交接
- 编程语言python特点-Python语言的特点有哪些?九大特点介绍!
- java学习--基础知识第六天--笔记
- linux-redhat替换yum网络源为centos网络源
- 前端学习(1844):前端面试题之vue的mvvm
- hdu-1877(大数+进制转换)
- c# 命名空间命名规范_C#命名空间能力问题和解答 套装3
- mysql中表格 列变行_MySQL数据透视表的列数据作为行
- 如何显示或隐藏Mac电脑右上角的声音图标
- php与mysql事物处理
- html pie标签,pie.html
- linux vim个人配色方案
- 经典的EDA设计软件Protel99SE
- Logistic模型
- “Defaulting to user installation because normal site-packages is not writeable“
- mysqldb 安装包 linux,Linux下Python MySQLdb模块安装过程及错误解决
- 计算机文件夹操作教案,文件文件和文件夹教案
- 计算机电源 4pin,用电脑电源4PIN接口做的2mm插头插座,省钱方便~
- word-wrap长单词与URL地址自动换行
- 二手车APP软件开发主要功能