欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Groovy - Groovy ambiguous method overload

程序员文章站 2022-07-15 13:04:56
...

修改前

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 语法。