I try to write following code:
Map<String, String> m = new HashMap<>();
// ... populate the map
m.entrySet().stream()
.sorted(Comparator.comparing(e -> e.getKey()).reversed())
.forEach(System.out::println);
This does not compile, because the inferred type for e
is Object
. However, if I remove the .reversed()
call, the inference works. I have to spell out the type for e
, which is ugly:
.sorted(Comparator.comparing((Map.Entry<String, String> e) -> e.getKey()).reversed())
Compiler can infer the type for Comparator.comparing
, but when I add reversed()
, it cannot. Why?