I currently have this function:
ImmutableMap<String, ImmutableList<ImpactSummary>> toSummariesByKey(ImmutableMap<String, ImmutableList<Impact>> impactsByKey) return impactsByKey.entrySet().stream() .collect( toImmutableMap( entry -> entry.getKey(), entry -> helper(entry.getValue())));} which makes use of this function:
ImmutableList<TierSummary> helper( ImmutableList<Impact> impacts) {...} As you can see, toSummariesByKey simply calls helper on each of the values in the input map.
Now, I need to modify toSummariesByKey to take as argument, and return, an ImmutableListMultimap instead:
ImmutableListMultimap<String, ImpactSummary> toSummariesByKey( ImmutableListMultimap<String, Impact> impactsByKey) {...} Reusing the body as is causes, when the helper function is called, the following error:
type
ImmutableList<Impact>is not compatible withImpact
However, helper is used in several places so I am reluctant to modify it. What is good practice in this scenario, please?
ImmutableMap. I’m guessing they come from Google Guava. But you should not make us guess.helperaccept a slightly more general argument type, likeList. Is that acceptable? I don't see why that would be an issue with modifying it, even if you have multiple users.