我尝试遵循Java 8 List转Map的方法,并尝试将一个列表中的Set更改为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_kprivate void methodAcceptingMap(Pair<Type, Boolean> pair, Parameters parameters)
。 - user7294900