【发布时间】:2017-01-31 02:35:21
【问题描述】:
我不明白为什么会失败;
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的第二个参数的类型是什么? -
不是函数。明白了,谢谢。
-
你可以直接用
Stream.of("1","2","3","4","5")代替Arrays.asList("1","2","3","4","5").stream()来表达你的意图。
标签: java collections lambda