我有没有办法做“$ -Strings”的嵌套评价Groovy中,例如像
def obj = {["name":"Whatever", "street":"ABC-Street", "zip":"22222"]}
def fieldNames = ["name", "street", "zip"]
fieldNames.each{ fieldname ->
def result = " ${{->"obj.${fieldname}"}}" //can't figure out how this should look like
println("Gimme the value "+result);
}
结果应该是:
Gimme the value Whatever
Gimme the value ABC-Street
Gimme the value 22222
。我试图要么解决这个不给正确的结果(例如刚刚obj.street}或将不能编译,我只是不明白的整个概念到目前为止,似乎但是,看到这个: HTTP:// groovy.codehaus.org/Strings+and+GString我相信它应该是可能的。