I am attempting to call the Apache Commons StringUtils.join() method from within a Groovy class. I want to concatenate 3 strings (part1
, part2
, and part3
).
Why doesn't this work?
def path = StringUtils.join([part1, part2, part3]) //1
But the following line works:
def path = StringUtils.join([part1, part2, part3] as String[]) //2
A follow up question. Why does this work? I am using StringUtils v 2.6, so it does not have a varargs method. Does groovy always convert method parameters to an array?
def path = StringUtils.join(part1, part2, part3) //3
This is largely a curiosity question. I am not going to use StringUtils because I posted a separate question yesterday and found a better solution. However, I would still like to understand why technique #1 does not work, yet #3 does work.