java - Java - 将子类赋予以父类为参数的方法
问题描述
ABTeacher
并且ABStudent
是子类ABUser
在applyStudentChange
我有Collection<ABStudent> ABStudents
我想打电话 changeABUser(Collection<ABUser> ABUsers)
, applyStudentChange
但我得到的集合是子类的集合,我应该怎么打电话changeABUser(Collection<ABUser> ABUsers)
?
我试过这样打电话changeABUser((Collection<ABUser>) ABStudents)
,这个演员表似乎不起作用......
解决方案
您需要为您的集合提供以下成员类型:
.... changeABUser(Collection<? extends ABUser> users) ....
推荐阅读
- python - 在 Python 中从 lambda 中提取多项式的系数
- android - 无法在 github 操作工作流程中使用“r0adkll/sign-android-release@v1”签署 AAB 文件
- php - mapbox的tilelayer png的缓存头
- c# - C#中的变量
- java - Java - 如何在不使用数组的情况下显示字符串中的所有子字符串
- java - 将微调器值设置为新的附加值
- php - 在 category.blade.php 中找不到类“App\model\Product”
- postgresql - postgres 不删除不为空
- php - Doctrine ResultSetMapping(Builder) 没有显示任何结果
- java - 如何让 JFileChooser 显示除 .huff 文件之外的所有类型的文件