I’m trying to turn Map<String, A>
into Map<String, B>
with a stream. I have a function that turns A into B, namely A.fromB()
.
This code is not working:
Map<String, A> aMap = some map
final Map<String, B> bMap =
aMap.keySet().stream()
.collect(Collectors.toMap(aKey -> aKey,
aKey -> aMap.get(aKey).stream()
.map(B::fromA)
.collect(Collectors.toList())));
I just got the following error from my IDE:
Required type: Map<String,B>
Provided: Map<Object,Object>
no instance(s) of type variable(s) T exist so that List conforms to B inference variable U has incompatible bounds: equality constraints: B lower bounds: List<T4192099>
What is the correct way to do this?
Dylan Gunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.