异常消息抱怨重复键,却显示值是什么原因?
List<Employee> employees = new ArrayList<>();
employees.add(new Employee("John", 40));
employees.add(new Employee("John", 30));
Map<String, Integer> map = employees.stream()
.collect(Collectors.toMap(Employee::getName, Employee::getAge));
不是显示“ John”作为重复键,而是显示“ 40”
Exception in thread "main" java.lang.IllegalStateException: Duplicate key 40
(...)