您的位置:首页 > 编程语言 > Java开发

【慕课笔记】第六章 JAVA中的集合框架(下) 第6节 尝试对学生序列排序

2016-03-02 15:34 525 查看
第6节 尝试对学生序列排序

public void testSort4(){
List<Student> stuList=new ArrayList<Student>();
stuList.add(new Student("1","小明"));
stuList.add(new Student("2","小红"));
stuList.add(new Student("3","小叉"));
System.out.println("--------------排序前---------------");
for (Student student : stuList) {
System.out.println("学生"+student.name);
}
Collections.sort(stuList);
}


最后一行报错了Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the arguments (List<Student>). The inferred type Student is not a valid substitute for the bounded parameter <T extends Comparable<? super T>>

原因是因为Student类没有继承Comparable类

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: