是否将动态语法设置为getProperty?

时间:2010-01-23 13:19:19

标签: groovy dynamic getproperty

这是可能的,如果,如何?

item.foo = "moo"

def x = "foo"
item.[x] = "moo"

1 个答案:

答案 0 :(得分:0)

我不确定我是否接受了你的问题,但是......

def item = {
    def foo
}
def x = "foo"
item[x] = "moo"

assert item[x] == "moo"
assert item.foo == "moo"