- 基本类型不能当对象使用
- 泛型不能使用instanceof

-
结果是true
image.png
image.png
image.png
-
image.png
泛型的约束和局限性
-可以声明泛型数组,但是不能实例化数组

-
不能捕获泛型对象
image.png
-
不能捕获,但是可以抛出,如下:
image.png
泛型类型的继承规则


通配符
- 用在方法参数上,不能用在类上
-
包括fruit的子类和fruit本身(类型的上界)
image.png

赋值

限定了传入参数的上界,可以取,但是不能设置
主要用于安全的访问数据,可以访问extends 后面的

? super Apple
- Apple的超类
主要是安全的写入数据

-
只能设置Apple 子类 【子类可以安全的转型为Apple】
image.png
-
返回类型只能是Object
image.png
虚拟机如何实现泛型
类型擦除
添加强制转型

网友评论