Skip to content

Instantly share code, notes, and snippets.

@nowelium
Created October 9, 2010 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nowelium/618242 to your computer and use it in GitHub Desktop.
Save nowelium/618242 to your computer and use it in GitHub Desktop.
var closures = List[() => String]()
for(i <- (1 to 5)) {
val localvar = "foo" + i
closures = {() => localvar } :: closures
}
closures.foreach { f => println(f()) }
// ==> foo5
// ==> foo4
// ==> foo3
// ==> foo2
// ==> foo1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment