Groovy - pass Set as varargs
def varargsMethod(String ... args){
args
}
Set set = ['a','b', 'c']
def array = varargsMethod(* (set as List))
assert (array as List).containsAll(set)
assert array instanceof String[]
Written by Baruch Sadogursky
Related protips
2 Responses
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/24715/de6eafe28472ceb9522fd3f609afed53.jpeg)
You can also do def array = varargsMethod( set as String[] )
over 1 year ago
·
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/51351/3d73332968c0bf62e1ece7299deb8b37.jpeg)
@tim_yates the power of Groovy (and protips :D)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Groovy
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#