Groovy - Groovy ambiguous method overload

阅读 41

2022-05-18


修改前

if (CollectionUtils.isEmpty(serviceGraph.getCallMap())) {
serviceGraph.setCallMap(new HashMap<String, Integer>())
}
Caused by: javax.script.ScriptException: groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.math.BigDecimal#<init>.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[class [Map]
[class java.util.Collection]


修改后

if (CollectionUtils.isEmpty(serviceGraph.getCallMap() as Map)) {
serviceGraph.setCallMap(new HashMap<String, Integer>())
}
  • Ps:成功!这里涉及到 Groovy 的 as 语法。


精彩评论(0)

0 0 举报