これはなぜ失敗するのでしょうか。マップのJavaラムダtoMap <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」の第2引数のタイプは何ですか? –
機能ではありません。了解、ありがとう。 –
'Arrays.asList(" 1 "、" 2 "、" 4 "、" 5 ").stream()'の代わりに 'Stream.of(" 1 "、" 2 " "3"、 "4"、 "5")を使用して直接あなたの意図を表現します。 – Holger