Groovy web console

subscribe to the feed Subscribe
to this
site

Closures in Loop

Published 2 months ago by Anonymous with tags Gotcha
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def closures = []
for (int i = 0; i < 5; i++) {
    closures += { println i }
}
closures.each{ it() }