What is the difference between these method signatures?
def myMethod = { //some code }
and
def myMethod () { //some code}
When would we want to use one over the other?
What is the difference between these method signatures?
def myMethod = { //some code }
and
def myMethod () { //some code}
When would we want to use one over the other?
1st one is a Closure
while the 2nd one is a plain method.
Usually you stick with methods, as they have smaller meta-overhead. A Closure costs a bit more (0.5%) in terms of performance, but it gives you more groovy power. You can use it as a variable in all collection methods for example, or chain the closures together. The later is used in GORM to build-up the criteria queries