Both are somewhat problematic from a performance perspective. I'd actually be tempted to do this in a "higher order function" style that returns a compiled construction function for the correct argument types, e.g. something like
(def double-builder (instantiator Double Long)) (double-builder 2) => 2.0 This allows you to take the pay the cost of compilation / reflection only once. On Thursday, 4 July 2013 11:57:32 UTC+1, Jim foo.bar wrote: > > (defmacro instantiate > "Returns an instance of the given class. Depending on the argument list will > invoke the corresponding constructor." > [cl-name & args] > `(eval (list 'new ~cl-name ~@args))) > > (defn new-instance "Create a new instance of the specified class using > reflection." > [^Class c & args] > (if (empty? args) (.newInstance c) > (.newInstance > (.getConstructor c (into-array (map class args))) > (to-array args)))) > > > any particular preference? > > Jim > > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.