jQuery in Action, 2nd edition
The moose likes Groovy and the fly likes Closures in Groovy Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Other Languages » Groovy
Reply Bookmark "Closures in Groovy" Watch "Closures in Groovy" New topic
Author

Closures in Groovy

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 8446

http://groovy.codehaus.org/Closures

Referring to the link above, what big difference does a closure makes when we compare it with a normal function?


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Josh Brown
Ranch Hand

Joined: Oct 09, 2007
Posts: 35
From the link above:

"Closures may be 'bound' to variables within the scope where they are defined"

In addition to that, you can pass a closure as an argument to a method. Then that method can call your closure. This means you can give a method some block of code, and the method can execute that block of code.

I'd recommend reading the Formal Definition on the Groovy site.
[ April 10, 2008: Message edited by: Josh Brown ]

Josh
Inside the Machine
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 8446

Hey, I got to understand this. Anyways, thanks for your reply!

Yesterday I bought the Groovy in Action book and started working on it already and it seems to be really interesting and now I'm fully exploring the Object Oriented concepts in Java through Groovy.
 
jQuery in Action, 2nd edition
 
subject: Closures in Groovy
 
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture