我知道Java,但对Groovy来说是全新的。 Groovy中有一些遗留代码可供使用。Groovy每个关闭错误
我有以下方法在Groovy:
def notificationPrefsByFruit = mapMyNotificationsByFruits(prefs, fruits)
当我mapMyNotificationsByFruits
方法在第一线调试,我得到prefs
为
def mapMyNotificationsByFruits(prefs,fruits) {
def map = [:]
prefs.each { MainNotification cn ->
cn.fruits.each {
MyNotification an ->
def ex = map[(an.fruitId)]
if (!ex) ex = []
ex.add(an)
map[(an.fruitId)] = ex
}
}
log.info("map is: $map")
return map
}
以上方法会从如下的另一种方法叫做
MainNotification [someId=ABC123, [email protected], fruits=[{fruitId=XYZ123, someField=0}]]
在运行这段代码时,我得到以下错误:
groovy.lang.MissingMethodException: No signature of method: com.somepackage.SomeClass$_mapMyNotificationsByFruits_closure5$_closure10.doCall() is applicable for argument types: (groovy.json.internal.LazyMap) values: [[{fruitId=XYZ123, someField=0}]]
这里有什么问题?
是什么,这些线做:
MyNotification an ->
def ex = map[(an.fruitId)]
if (!ex) ex = []
ex.add(an)
map[(an.fruitId)] = ex
它是一个铸造的问题?
更换上面下面的代码行解决问题:
MyNotification an = it
def ex = map[(an.fruitId)]
if (!ex) ex = []
ex.add(an)
map[(an.fruitId)] = ex
但我不知道,如果这两个代码块是相同的,我是正确的修复它。
在此先感谢!
什么是输入和预期输出? – Rao
您没有提供足够的信息,但试图解决您的问题。 – dsharew