Skip to content

Instantly share code, notes, and snippets.

@hallettj
Created February 6, 2011 06:05
Show Gist options
  • Save hallettj/813178 to your computer and use it in GitHub Desktop.
Save hallettj/813178 to your computer and use it in GitHub Desktop.
Groovy supports true closures
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