【发布时间】:2020-10-05 15:22:41
【问题描述】:
我有一个小问题。
假设我们有Person 是一个接口,Student 是一个抽象类,UnderGrad 是一个实现Person 并扩展Student 的普通类。
然后,在另一个班级中,有一个学生数组,即Student[],其中仅包含UnderGrad 对象。
在那个类中,有一个静态方法,它以Person[] 为参数,并按年龄对它们进行排序。
public static sortStudents(Person[] people) {
// It sorts them
}
如何将充满UnderGrads 的数组Student[] 转换为由UnderGrad 实现的Person[] 数组?
【问题讨论】:
-
一种方法是让您的
Student类实现Person而不是Undergrad。
标签: java sorting user-interface casting abstract