Skip to content

Instantly share code, notes, and snippets.

@fumokmm
Created September 3, 2011 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumokmm/1191220 to your computer and use it in GitHub Desktop.
Save fumokmm/1191220 to your computer and use it in GitHub Desktop.
Using closure for temporary block.
@groovy.transform.Canonical
class Person{ def name }
List<Person> list = {def list = []; ['taro', 'jiro', 'sabuchan'].each{list << new Person(it)}; list }()
List<Person> list2 = ['taro', 'jiro', 'sabuchan'].collect{ new Person(it) }
assert list == list2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment