【发布时间】:2020-10-14 07:53:05
【问题描述】:
以下是正在使用的具有 lombok @Data 注释的 bean:
@Data
public class XxedgeCrtV implements Serializable {
private static final long serialVersionUID = 1L;
private String registryId;
private String personPartyId;
private String source;
private String compositeKey() {
return registryId + personPartyId + source;
}
}
当我尝试在复合键上使用 Java 8 创建 hashmap 时,它不会读取该方法:
Set<String> duplicates = xxedgeCrtVList.stream()
.collect(Collectors.groupingBy(XxedgeCrtV::compositeKey, Collectors.counting()))
.entrySet().stream()
.filter(e -> e.getValue() > 1L)
.map(e -> e.getKey())
.collect(Collectors.toSet());
谁能建议如何让代码读取这个方法?
我正在制作复合键的键,因为我必须在列表中搜索重复项。
【问题讨论】:
-
因为它是
private,如果你想从另一个类调用它,就让它成为public -
我尝试在复合键上使用 Java 8 创建 hashmap,共享的代码不涉及
Map!顺便说一句,您也不能在Set中收集重复项。
标签: java java-8 java-stream lombok collectors