作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这可能看起来是一个愚蠢的问题(因为它可能非常特定于项目),但在这种情况下它足够普遍:
我正在运行一段代码,给出 ClassCastException
,我写的错误消息是标题。这里提到的强制转换来自 java.lang.reflect.Type
类型的对象至Class<?>
.
除了基本类型之外,Java 中哪种类型不是类?
感谢您的回答
最佳答案
一个Class
是 Type
但是一个Type
没有必要 Class
,自 Class
implements Type
.
基本上,您的myType
也可以是接口(interface) GenericArrayType
的任何实现类, ParameterizedType
, TypeVariable
或 WildcardType
,因为它们都扩展了 Type
界面。
尝试打印 myType.getClass()
查看您所指的类型:您将得到 Class<TheSaidType>
.
关于java - "Cannot be cast to java.lang.Class",即: which type is not a class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14590467/
我是一名优秀的程序员,十分优秀!