Я не понимаю, почему это не удается;Java lambda toMap of map <String, Boolean>
Map<String, Boolean> iMap = Arrays.asList("1","2","3","4","5").stream()
.collect(Collectors.toMap(k->k, Boolean.TRUE));
сообщение об ошибке:
Multiple markers at this line
- Type mismatch: cannot convert from T to K
- The method toMap(Function<? super T,? extends K>, Function<? super T,? extends U>)
in the type Collectors is not applicable for the arguments ((<no type> k) -> {}, Boolean)
Любая помощь приветствуется.
Каков тип второго аргумента 'toMap'? –
Не функция. Понял, спасибо. –
Вместо 'Arrays.asList (« 1 »,« 2 »,« 3 »,« 4 »,« 5 »). Stream()', вы можете использовать 'Stream.of (« 1 »,« 2 », «3», «4», «5») ', чтобы выразить свое намерение напрямую. – Holger