Code inside closures can refer to it
variable.
8.times { println it }
or
def mywith(Closure closure) {
closure()
}
mywith { println it }
With this behavior in mind you can't expect following code to print 0011
2.times {
println it
mywith {
println it
}
}
And instead I have to write
2.times { i ->
println i
mywith {
println i
}
}
My question is: why closures without parameters override it
variable even if they don't need it.