Map map = new HashMap();
List numList = map.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getValue).reversed()) //this part
.map(Map.Entry::getKey)
.toList();
< /code>
ошибка: < /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>
Но почему следующие фрагменты работают нормально? < /p>
два < /p>
Map map = new HashMap();
List numList = map.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getValue).reversed())
.map(Map.Entry::getKey)
.toList();
< /code>
три < /p>
Map map = new HashMap();
List numList = map.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getValue))
.map(Map.Entry::getKey)
.toList();
Почему следующее вызывает ошибку компиляции? < /p> One < /p> [code]Map map = new HashMap(); List numList = map.entrySet().stream() .sorted(Comparator.comparing(Map.Entry::getValue).reversed()) //this part .map(Map.Entry::getKey) .toList(); < /code> ошибка: < /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> Но почему следующие фрагменты работают нормально? < /p> два < /p> Map map = new HashMap(); List numList = map.entrySet().stream() .sorted(Comparator.comparing(Map.Entry::getValue).reversed()) .map(Map.Entry::getKey) .toList(); < /code> три < /p> Map map = new HashMap(); List numList = map.entrySet().stream() .sorted(Comparator.comparing(Map.Entry::getValue)) .map(Map.Entry::getKey) .toList(); [/code] Похоже, что сортировка () нуждается в компараторе