DEV Community

Manav Misra
Manav Misra

Posted on

1

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay