It seems to refer to the Bird class, but how does this fit into Groovy closures and the implementation of the language as a whole?
To answer the above, it does refer to instance of Bird
. It acts similar to this
operator but outside the context of the wrapped object denoted by this
. This can be explained with a small example:
Integer.metaClass.sayHello = {
return "Say hello $delegate times"
}
assert 2.sayHello() == "Say hello 2 times"
assert 20.sayHello() == "Say hello 20 times"
Integer.metaClass.sayHi = {
return "Say hello $this times"
}
println 2.sayHi()
Mark at the last println if you are running in Groovy Console. this
operator represents the script on which you run the above code.
In addition to the above explanation, do visit the links provided in my comment.