DEV Community

Manav Misra
Manav Misra

Posted on

Answer: What is the type of Map.Entry.comparingByValue().reversed()? [duplicate]

When you shorten down

Comparator<Entry<String, Integer>> cmp = Entry.comparingByValue();
entries.sort(cmp.reversed());

to

entries.sort(Entry.comparingByValue().reversed());

you remove the type information gleaned from cmp’s declaration. The compiler still needs to know that information, so you need to add the generic typing to Entry:

entries.sort(Entry.<String, Integer>comparingByValue().reversed());

Top comments (0)