【发布时间】:2020-04-08 01:12:07
【问题描述】:
我尝试关注Java 8 List into Map 并尝试在一个列表中更改设置为地图
而不是循环(有效)
for (Type t : toSet()) {
map.put(Pair.of(t, Boolean.TRUE), this::methodAcceptingMap);
}
我尝试了以下解决方案:
toSet().stream()
.collect(Collectors.toMap(Pair.of(Function.identity(), Boolean.TRUE),
this::methodAcceptingMap));
但转换时出错:
Type mismatch: cannot convert from Pair<Function<Object,Object>,Boolean>
to Function<? super T,? extends K>
我的地图
private Map<Pair<Type, Boolean>, BiConsumer<Pair<Type, Boolean>, Parameters>> map =
new HashMap<>();
【问题讨论】:
-
可以分享
methodAcceptingMap的签名吗? -
@ernest_k 我认为方法现在无关紧要,但这里是
private void methodAcceptingMap(Pair<Type, Boolean> pair, Parameters parameters)
标签: java dictionary java-8 set java-stream