You can use @Delegate, as shown below, that delegates these method calls List:
class Test {
@Delegate List myList
}
new Test(myList: [1, 2, 3]).each { println it }
new Test(myList: ['a', 'b', 'c']).eachWithIndex { val, index ->
println "$val at $index"
}
source
share