I'm trying to stream a list of Doubles into a Map<Double, Double>, where the keys are the Doubles in the original list, and the values are some computed value.
This is what my code looks like:
// "values" is a List<Double> that was passed in
ImmutableMap<Double, Double> valueMap = values.parallelStream()
.collect(Collectors.toMap(p -> p, p -> doThing(values, p)));
private Double doThing(List<Double>, Double p) {
Double computedValue = 0.0;
// Do math here with p
return computedValue;
}
However, IntelliJ is complaining that p -> p is not a valid lambda expression - it's complaining about a cyclic inference. I'm also getting an error when I call doThing, because p is a lambda parameter and not a Double.
When I try to cast p to a Double in the call to doThing, that fails to cast.
Am I missing something really obvious? It seems like there's no way to actually do anything with my lambda parameters...