我的问题是:给定人员列表,返回所有学生。
这是我的课程:
人类
public class Person {
}
Run Code Online (Sandbox Code Playgroud)
学生班
public class Student extends Person {
}
Run Code Online (Sandbox Code Playgroud)
方法
public static List<Student> findStudents(List<Person> list) {
return list.stream()
.filter(person -> person instanceof Student)
.collect(Collectors.toList());
}
Run Code Online (Sandbox Code Playgroud)
我收到一个编译错误: incompatible types: inference variable T has incompatible bounds
如何使用流从列表中返回所有学生,而不会出现此错误。