Is there some way to use default parameters values with closures in Groovy?
This is what I tried so far:
class Persona { String name Persona( String name ) { this.name = name } String salute( String salute = 'Hola' ) { salute + ' ' + this.name } } Persona.metaClass.salute2 = { String salute = 'Hola' -> salute + ' ' + name } p = new Persona( 'john' ) print p.salute() print p.salute2()
which gives me the following result:
Hola johnnull john
It seems like the call to salute2() is ignoring the salute default value 'Hola'.
Your code is working fine as you expected with Groovy 1.6-RC2.