尝试使用 Java 流基于列表创建地图时无法修复错误

Cannot fix error when trying to create a map based on a list using Java streams

我正在尝试使用值数组列表创建哈希图。

//Map to store collected values in    
Map<String, Boolean> stringMap = new HashMap<>();

//List of strings to use to make map
ArrayList<String> strings = getStrings();

stringMap = strings.stream()
.collect(Collectors.toMap(Function.identity(), new Boolean.FALSE));

我一直在 .collect 行收到错误,我认为这与将映射中的每个布尔值设置为 false 有关。

我看过关于流的教程,它应该可以工作:

我知道和布尔值有关。我已经尝试将 false 放在那里或 Boolean.valueOf(FALSE) 和其他一些东西来解决这个问题,但我不断收到错误。

您需要提供一个 Function<> 作为第二个参数:

stringMap = strings.stream()
     .collect(Collectors.toMap(Function.identity(), b -> Boolean.FALSE));