Created
February 6, 2011 06:05
-
-
Save hallettj/813178 to your computer and use it in GitHub Desktop.
Groovy supports true closures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def makeClos() { | |
def x = 0; | |
def close = { x += 1; println(x) } | |
close | |
} | |
def closA = makeClos() | |
def closB = makeClos() | |
closA() // prints 1 | |
closA() // prints 2 | |
closA() // prints 3 | |
closB() // prints 1 | |
closB() // prints 2 | |
closA() // prints 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment