Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2012 03:46
Show Gist options
  • Save anonymous/1857262 to your computer and use it in GitHub Desktop.
Save anonymous/1857262 to your computer and use it in GitHub Desktop.
closure example
def hoge() {
int data = 1
return {x -> if (x==1){data=10;return data}else{return data}}
}
clos = hoge()
assert clos.call(3) == 1
assert clos.call(1) == 10
assert clos.call(3) == 10
clos = hoge()
assert clos.call(3) == 1
assert clos.call(1) == 10
assert clos.call(3) == 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment