Probably the spread operator, *
, is what you’re looking for:
def to(String... emails) {
emails.each { println "Sending email to: $it"}
}
def emails = ["t@a.com", "t@b.com", "t@c.com"]
to(*emails)
// Output:
// Sending email to: t@a.com
// Sending email to: t@b.com
// Sending email to: t@c.com
Notice that the parentheses on the method call to to
are mandatory, as otherwise to *emails
would be parsed as a multiplication. Bad choice of overloaded grammar symbols IMO =P