我'm trying to create a Groovy class that delegates to a ConfigObject property, while it still has a couple properties of it'拥有 . 出于某种原因,我无法让它正常工作 . 从 @Delegate
注释的文档中,看起来应该调用已在所有者类上定义的任何方法,并将 not 委托给delegate属性 . 这里有什么特别之处,因为ConfigObject类实现了Map接口吗?
class ApplicationProperties {
@Delegate(excludes = ["clone", "serverName", "serverIpAddress"])
ConfigObject configData
String serverName = "foo"
String serverIpAddress = "bar"
}
调用 applicationProperties.serverName
不返回foo,它将返回null,因为它委托给configData实例变量 . 我似乎有所作为 . 如果我设置 interfaces = false
然后serverName属性正常工作,但似乎没有其他任何东西委托给ConfigData . 我有什么想法我做错了吗?
1 回答
如果您引用应评估为"foo"的
applicationProperties.getServerName()
.