Eines < /p>
Code: Select all
Map map = new HashMap();
List numList = map.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getValue).reversed()) //this part
.map(Map.Entry::getKey)
.toList();
< /code>
Fehler: < /p>
java: incompatible types: cannot infer type-variable(s) T,U
(argument mismatch; invalid method reference
method getValue in interface java.util.Map.Entry cannot be applied to given types
required: no arguments
found: java.lang.Object
reason: actual and formal argument lists differ in length)
< /code>
Aber warum funktionieren die folgenden Ausschnitte gut? < /p>
Zwei < /p>
Map map = new HashMap();
List numList = map.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getValue).reversed())
.map(Map.Entry::getKey)
.toList();
< /code>
drei < /p>
Map map = new HashMap();
List numList = map.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getValue))
.map(Map.Entry::getKey)
.toList();