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

来源:互联网 发布:浙江大学软件学院面试 编辑:程序博客网 时间:2024/05/22 08:49

第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类


0 0