Java 11 将字符串列表转换为映射<UUID,String>
Java 11 Convert List of Strings to Map<UUID,String>
我正在尝试将字符串列表转换为 Map,如下所示,但出现编译错误 no instance(s) of type variable(s) K, T exist so that UUID conforms to Function<? super T, ? extends K>
,有人可以帮我解决这个问题吗?
List.of("john","jack", "jill")
.stream()
.collect(Collectors.toMap(UUID.randomUUID(), name ->name));
Map<UUID, String> collect =
List.of("john", "jack", "jill")
.stream()
.collect(Collectors.toMap(k -> UUID.randomUUID(), name -> name));
我正在尝试将字符串列表转换为 Map,如下所示,但出现编译错误 no instance(s) of type variable(s) K, T exist so that UUID conforms to Function<? super T, ? extends K>
,有人可以帮我解决这个问题吗?
List.of("john","jack", "jill")
.stream()
.collect(Collectors.toMap(UUID.randomUUID(), name ->name));
Map<UUID, String> collect =
List.of("john", "jack", "jill")
.stream()
.collect(Collectors.toMap(k -> UUID.randomUUID(), name -> name));