如何访问多参数设置器的 Groovy 设置器快捷方式?

发布于 2024-07-25 20:24:19 字数 214 浏览 1 评论 0原文

假设我有一个 java.util.Properties 对象。 Properties 对象有一个名为 setProperty(String name,String value) 的方法。 有它的设置器快捷方式吗?

编辑:也许 Properties 类不是最好的例子,因为我认为它通过添加键作为属性来处理这个问题。 但是如果一个 setter 方法接受任意数量的参数呢?

Let's say I have a java.util.Properties object. The Properties object has a method called setProperty(String name,String value). Is there a setter shortcut for it?

EDIT: maybe the Properties class was not the best example, because I think it handles that by adding the keys as properties. But how about a setter method that takes an arbitrary number of parameters?

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

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

发布评论

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

评论(1

路还长,别太狂 2024-08-01 20:24:19

最简洁的答案是不'。 Groovy 仅提供遵循 JavaBeans 约定的 getter/setter 属性的快捷方式,

T getX()

void setX(T value)

其中 X 是属性的名称,T 是属性的类型。 名为“set*”且具有多个参数的方法不符合条件。

The short answer is 'no'. Groovy only provides shortcuts for getters/setters properties which follow the JavaBeans convention

T getX()

void setX(T value)

where X is the name of the property and T is the type of the property. Methods that are named "set*" and have more than one argument do not qualify.

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