当前位置: 首页 > 工具软件 > groovy-http > 使用案例 >

Groovy - Groovy ambiguous method overload

陆文斌
2023-12-01

修改前

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 语法。 
 类似资料: