我已经编码了这个:this.referenceService.get(id)
.map(Reference::hashCode)
.map(Integer::toString);我收到此编译错误:模棱两可的方法参考:来自 Integer 类型的 toString() 和 toString(int) 都符合条件我该如何解决这个问题?
1 回答

慕村225694
TA贡献1880条经验 获得超4个赞
您有两种可能的解决方案:
用 lambda 替换它:
this.referenceService.get(id)
.map(ref-> Integer.toString(ref.hashCode()));
使用Objects.toString()
this.referenceService.get(id)
.map(Reference::hashCode)
.map(Objects::toString); // this will cal toString method on you hash
编写自己的方法:
this.referenceService.get(id)
.map(this::toHashString);
private Strign toHashString(Reference ref) {
return Integer.toString(ref.hashCode());
}
添加回答
举报
0/150
提交
取消