时髦名单传播 [英] groovy list spreading
问题描述
如果运行以下Groovy代码,断言将通过
If you run the following Groovy code, the assertion passes
def foo(a, b) {
a + b
}
assert 'aaabbb' == foo(['aaa', 'bbb'])
这表明如果使用包含X元素的List参数调用某个方法,那么List将被传播,并且将调用一个带有X参数的方法。
This suggests that if a method is called with a List parameter that contains X elements, then the List will be spread and a method with X arguments will be invoked.
当然,这只会在没有使用List(或其祖先)类型的单个参数定义的方法时才会发生。
Of course, this will only happen if there isn't a method defined with a single parameter of type List (or ancestor thereof).
在阅读另一篇SO Groovy答案时,我最近才发现这一点。我从未在Groovy文档,发行说明或书籍中看到过它。它是一个隐藏的功能,一个错误,或只是我错过了什么?
I only discovered this quite recently when reading another SO Groovy answer. I've never seen it mentioned in the Groovy docs, release notes, or books. Is it a hidden feature, a bug, or just something I've missed?
推荐答案
显然将在Groovy 2中被删除:
http:// groovy。 329449.n5.nabble.com/removing-features-in-Groovy-2-td4422494.html
Going to be removed in Groovy 2 apparently: http://groovy.329449.n5.nabble.com/removing-features-in-Groovy-2-td4422494.html
JT是第一个在删除名单上的似乎Groovy用户的每个人(充满感召力)都表示同意。
JT's first on the to-remove list and it seems everyone (with clout) on Groovy User agrees.
这篇关于时髦名单传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!