Reputation: 7886
I know that I implement a Java interface in Clojure using proxy like this:
(def print-element-handler
(proxy [DefaultHandler] []
(startElement [uri local qname atts]
(println (format "Saw element: %s" qname)))))
Note that there are four args, [uri local qname atts], for the four args in the interface method, startElement.
Suppose a method in a Java interface has a variable number of args like this:
List<Task> getTasks(Object... args);
What do I put for the arg list in the corresponding Clojure function?
Upvotes: 4
Views: 661
Reputation: 22415
I am not 100% certain, as I am not able to test it out at the moment, but I believe the answer is you just have a single parameter for the array. I know for a fact that when you call a Java method with varags, you have to convert the Clojure collection into an array before passing it in. I imagine it's no different here.
For an example, here is the source for format
:
(defn format
"Formats a string using java.lang.String.format,
see java.util.Formatter for format string syntax"
{:tag String
:added "1.0"}
[fmt & args]
(String/format fmt (to-array args)))
Upvotes: 4