Last Updated: September 09, 2019
·
6.915K
· jbaruch

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[]

2 Responses
Add your response

You can also do def array = varargsMethod( set as String[] )

over 1 year ago ·

@tim_yates the power of Groovy (and protips :D)

over 1 year ago ·