假设我有以下 Groovy 代码:
class Human {
Face face
}
class Face {
int eyes = 2
}
def human = new Human(face:new Face())
我想使用[]
访问eyes
属性:
def humanProperty = 'face.eyes'
def value = human[humanProperty]
但是这并没有像我期望的那样工作(因为它试图在Human对象上访问一个名为'face.eyes'的属性,而不是human.face属性中的eyes属性)。
还有其他的方法吗?