我正在尝试使用stream()并放入地图来迭代列表,其中键是 steam 元素本身,值是 AtomicBoolean,true。
List<String> streamDetails = Arrays.asList("One","Two");
toReplay = streamDetails.stream().collect(Collectors.toMap(x -> x.toString(), new AtomicBoolean(true)));
Run Code Online (Sandbox Code Playgroud)
我在编译时收到以下错误。
Type mismatch: cannot convert from String 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> x) -> {},
AtomicBoolean)
Run Code Online (Sandbox Code Playgroud)
我可能做错了什么,我应该用什么x -> x.toString()来代替?