What is the difference between Comparator::reverseOrder
and Comparator.reverseOrder()
when used in sorted method of stream.
Stream<String> streamText = Stream.of("over the river", "through the woods", "to grandmother's house we go");
This works:
streamText.filter(n -> n.startsWith("t"))
.sorted(Comparator.reverseOrder())
.findFirst().ifPresent(System.out::println);
But this does not compile:
streamText.filter(n -> n.startsWith("t"))
.sorted(Comparator::reverseOrder)
.findFirst().ifPresent(System.out::println);