【慕课笔记】第六章 JAVA中的集合框架(下) 第6节 尝试对学生序列排序
2016-03-02 15:34
525 查看
第6节 尝试对学生序列排序
最后一行报错了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类
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类
相关文章推荐
- Struts1——从BeanUtils看struts的实现原理2
- 回调函数理解的整理(某知乎大神写的)
- java与&或|非~运算
- 一个经典例子让你彻彻底底理解java回调机制
- JAVA 并发编程-应用篇
- JTextArea行号显示工具类
- eclipse中如何给main函数的参数args赋值
- java语言:方法重载&方法重写&继承
- Java基础学习之路
- JAVA 变量的3种形式
- java 空指针异常其他原因
- Spring注解解析
- pro02总结:spring mvc + jdbc
- java小游戏第二弹 打地鼠
- MyEclipse6.5安装SVN插件方法
- SPRING SECURITY JAVA配置:Web Security
- java基础-取余数,取商
- ElasticsSearch——部署环境(JDK)
- JVM调优总结
- 搭建Maven环境