如何访问多参数设置器的 Groovy 设置器快捷方式?
假设我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简洁的答案是不'。 Groovy 仅提供遵循 JavaBeans 约定的 getter/setter 属性的快捷方式,
其中 X 是属性的名称,T 是属性的类型。 名为“set*”且具有多个参数的方法不符合条件。
The short answer is 'no'. Groovy only provides shortcuts for getters/setters properties which follow the JavaBeans convention
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.