Java泛型不能使用instanceOf

杨采妮 Java教程 发布时间:2022-05-31 21:37:19 阅读数:3603 1
下文笔者讲述java泛型不能使用instanceOf方法的简介说明,如下所示
由于编译器使用类型擦除,
所以运行时无法跟踪类型参数,所以不能使用instanceOf运算符
  
InfoClass<Integer> integerInfoClass = new InfoClass<Integer>();

//Compiler Error:
//Cannot perform instanceof check against
//parameterized type InfoClass<Integer>.
//Use the form InfoClass<?> instead since further
//generic type information will be erased at Runtime
if(integerInfoClass instanceof InfoClass<Integer>) { }
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/JavaCourse/202205/3591.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者