私はJavaを知っていますが、Groovyは全く新しいです。 Groovyにいくつかのレガシーコードがあります。Groovy closure error
私はGroovyでメソッドの下にあります。上記の方法
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
}
は、以下のように別のメソッドから呼び出されます:
def notificationPrefsByFruit = mapMyNotificationsByFruits(prefs, fruits)
私はmapMyNotificationsByFruits
方法で最初の行にデバッグするとき、私は
prefs
を取得
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