Why does Collectors.toMap report value instead of key on Duplicate Key error?

后端 未结 5 1719
春和景丽
春和景丽 2020-11-30 13:31

This is really a question about a minor detail, but I\'m under the impression to get something wrong here. If you add duplicate keys using Collectors.toMap-method it throws

5条回答
  •  我在风中等你
    2020-11-30 14:10

    This is reported as a bug, see JDK-8040892, and it is fixed in Java 9. Reading the commit fixing this, the new exception message will be

    String.format("Duplicate key %s (attempted merging values %s and %s)", k, u, v)
    

    where k is the duplicate key and u and v are the two conflicting values mapped to the same key.

提交回复
热议问题