0

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?

Anonymous Human
  • 1,858
  • 1
  • 21
  • 47
  • http://stackoverflow.com/questions/15602501/differences-between-action-and-methods-in-grails-controllers – MKB Jun 03 '14 at 13:15
  • http://stackoverflow.com/questions/9205209/why-should-grails-actions-be-declared-as-methods-instead-of-closures-and-what-di?lq=1 – MKB Jun 03 '14 at 13:16
  • 1
    possible duplicate of [Groovy : Closures or Methods](http://stackoverflow.com/questions/1825424/groovy-closures-or-methods) – lukelazarovic Jun 03 '14 at 13:26

1 Answers1

-1

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

injecteer
  • 20,038
  • 4
  • 45
  • 89