import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class testSort {
public static void main(String[] args) {
Student stu1=new Student("zhangsan",18);
Student stu2=new Student("lisi",20);
Student stu3=new Student("wangba",31);
Student stu4=new Student("zhaoliu",17);
List<Student> stu=new ArrayList<Student>();
stu.add(stu1);
stu.add(stu2);
stu.add(stu3);
stu.add(stu4);
System.out.println("原始数据:");
for (Student student : stu) {
System.out.println(student);
}
System.out.println("进行排序......");
ComparatorSort com=new ComparatorSort();
Collections.sort(stu, com);
for (Student student : stu) {
System.out.println(student);
}
Student maxstu=Collections.max(stu);
System.out.println(maxstu);
}
}
这段代码前面排序都好使,就max出错误,说是max括号内的类型不匹配.stu应当继承自一个泛型.那就是Colections.max()无法使用.
绝地无双
相关分类