Advertisement
fatimacasau

closures 1

Jul 25th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 0.33 KB | None | 0 0
  1. // closure sin argumentos
  2. def hola = {println "hola"}
  3. hola()
  4.  
  5. // closure con un sólo argumento
  6. def saludo = {println "hola $it"}
  7. saludo("Fátima")
  8.  
  9. // closure con dos argumentos
  10. def printSum = { a, b -> println a+b }
  11. printSum( 5, 7 )
  12.  
  13. // closure con variables libres
  14. def a = 10
  15. def sum10 = { it + a}
  16. println sum10(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement