java8 stream里面thenComparing里面写不写Comparator对排序逻辑有什么影响?

test.stream().sorted(Comparator.comparing(Worker::getAge).reversed()
.thenComparing(Worker::getName).reversed()
.thenComparing(Worker::getSalary))
.collect(Collectors.toList())
.forEach(System.out::println);


test.stream().sorted(Comparator.comparing(Worker::getAge).reversed()
.collect(Collectors.toList())
.forEach(System.out::println);
相比,年龄的倒序没出来。

上面那两个其实都可以实现年龄倒序,thenComparing在你的程序里代表,如果年龄相同就比较xx,进行升序排序
但是你的第二个是不是有问题啊,少写了一个),程序应该有报错吧?

img

https://www.cnblogs.com/YuyuanNo1/p/13885103.html https://www.cnblogs.com/YuyuanNo1/p/13885103.html