toMap - bug

原因:AttachmentInfoRespnse::getAssociateKeyId 作为键重复了,代码没有指定如何处理

//Duplicate key:错误代码
final Map<Long,String> keyIdWithPathMap = attachmentInfoResponse.stream().collect(Collections.toMap(AttachmentInfoRespnse::getAssociateKeyId, item -> Optional.of(item.getxxx()).orElse)))


//解决代码:toMap第三个参数可以指定当key 重复的时候值怎么取
final Map<Long,String> keyIdWithPathMap = attachmentInfoResponse.stream().collect(Collections.toMap(AttachmentInfoRespnse::getAssociateKeyId, item -> Optional.of(item.getxxx()).orElse),(v1,v2) -> v1);

https://blog.csdn.net/weixin_44422604/article/details/119888769

posted @ 2024-01-19 17:05  chuangzhou  阅读(11)  评论(0)    收藏  举报