l a s
l a s

Reputation: 3923

Groovy dynamic variables' value

I have a groovy script as given below. I have defined a list which contains dynamic variables. The dynamic variables hold different values. how do i print the values of the variables - I don't want to hardcode this.var0. Please help.

someList = []

for (i in 0..2) {
    someList[i] = "var${i}"
}

var0 = "test1"

// print the values of the variables in the list
println this.someList[0]

Upvotes: 1

Views: 3615

Answers (1)

dmahapatro
dmahapatro

Reputation: 50245

The value from someList[0] has to be interpolated as well. Try:

println this."${someList[0]}"

Upvotes: 1

Related Questions