Slightly deceiving error message on Collectors.toMap
Michael Nascimento
misterm at gmail.com
Thu Apr 17 16:37:48 UTC 2014
On Thu, Apr 17, 2014 at 1:04 PM, Peter Levart <peter.levart at gmail.com> wrote:
> But the two values are the same (if the key->value mapper function *is* a
> function), aren't they?
No, for example:
Stream.of(1, 1).collect(toMap(identity(), i -> Math.random()));
Another example would be something like:
cities.stream().collect(toMap(City::getName, identity()));
If there are cities from different states in the collection, their
names might collide. Printing both values (with a decent toString)
will help developers to figure out their mistake.
Regards,
Michael
More information about the lambda-dev
mailing list