Given following code:
@Test
public void test7() {
Map<String, Integer> sortedData = new HashMap<>();
sortedData.put("One", 1);
sortedData.put("Two", 2);
sortedData.put("Three", 3);
Stream<Map.Entry<String, Integer>> stream = sortedData.entrySet().stream();
List<String> sorted = stream
.sorted(Comparator.comparing(Map.Entry::getValue))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
}
It succeeds to compile, but when I change
.sorted(Comparator.comparing(Map.Entry::getValue))
to
.sorted(Comparator.comparing(Map.Entry::getValue).reversed())
the compiler complains that Non static method can't be referenced in static context
I could imagine that it is because getValue
is not a static method of Map.Entry
, but I can't explain the problem here.