Hi Vincent,

In general, varargs parameters can be invoked similarly as functions
with arrays, but it can be tricky to prepare the arguments in a way
that they will be passed on as arrays. An explicit array conversion
may help. This Java code…

ArrayList<String> list = new ArrayList<>();
list.add("a");
list.add("b");
System.out.println(String.join("/", list.toArray(String[]::new)));

…can be written as:

declare namespace list = 'java.util.ArrayList';
let $list := list:new()
where list:add($list, 'a')
where list:add($list, 'b')
let $array := list:toArray($list)
(: with types: "join·CharSequence·CharSequence..." :)
return Q{java.lang.String}join('/', $array)

When the code gets more complex, it’s still more convenient to write
an additional Java wrapper class.

Hope this helps,
Christian

Reply via email to