Groovy Expando 动态集名称

发布于 2024-09-12 14:48:30 字数 237 浏览 3 评论 0原文

是否可以动态设置扩展的类?

设置后

jr = new Expando()

办法

def end = 'name'

有没有

jr.end

让我真正得到存储在中的值

jr.name

Is it possibly to dynamically set the class of an expando??

Having set

jr = new Expando()

Is there a way to

def end = 'name'

so that

jr.end

will actually give me the value stored in

jr.name

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

讽刺将军 2024-09-19 14:48:30

我不确定我是否理解你的问题,也许这会有所帮助

jr = new Expando()
jr.end = 'name'
jr.name = jr.end

assert jr.end == jr.name
assert jr.end == 'name'

I'm not sure I understand your question, maybe this will help

jr = new Expando()
jr.end = 'name'
jr.name = jr.end

assert jr.end == jr.name
assert jr.end == 'name'
束缚m 2024-09-19 14:48:30

修复了,需要同时赋值。哎哟!

def value = 'some value'
jr."$end" = value

fixed it, need to assign a value at the same time. Doh!

def value = 'some value'
jr."$end" = value
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文