Reputation: 335
Is it possible to call methodTwo() as in
def map = [methodOne: { return "${methodTwo()}" }, methodTwo: { return "Hey" }] as MyInterface
methodTwo cannot be found at runtime by groovy (it seems that it is searching its definition inside the class where the map was defined)
Upvotes: 2
Views: 258
Reputation: 14559
You can call the method declaring the map
variable before, and then referencing it:
interface MyInterface {
def methodOne()
def methodTwo()
}
def map
map = [
methodOne: { return "${map.methodTwo()}" },
methodTwo: { return "Hey" }
] as MyInterface
assert map.methodOne() == "Hey"
Upvotes: 2