Reputation: 313
I have a Java class with a constructor taking a variable number of String arguments like this:
public Foo(String...args);
I'm trying to create a make-foo multimethod in Clojure to handle this:
(defmethod make-foo clojure.lang.ArraySeq [& args] (new Foo (into-array args)))
But when I call it with
(make-foo ["one" "two"])
I get: IllegalArgumentException No matching ctor found
I'd also like to be able to call it with
(make-foo '("one" "two"))
I see there are to-array variants for ints, floats, etc, but no String. So how do I handle this case?
Upvotes: 2
Views: 515
Reputation: 91907
make-foo
as written would work if you called it like (make-foo "one" "two")
, or you could remove the &
from its definition and then pass it sequences.
Upvotes: 2