list = list.stream().sorted(Comparator.comparing(Student::getAge).reversed()).collect(Collectors.toList());
如果此处的Student对象中的age字段,数据类型为Integer,则会报空指针异常;
将数据类型改为int,则可以正常排序。
list = list.stream().sorted(Comparator.comparing(Student::getAge).reversed()).collect(Collectors.toList());
如果此处的Student对象中的age字段,数据类型为Integer,则会报空指针异常;
将数据类型改为int,则可以正常排序。