Ah, makes sense now, thank you. I know the parameter list will be one of three possibilities, so probably makes more sense to specify the conditions than to use reflection. I don't have a repl handy, but either of the below should work:
;; using apply (per Konrad) (cond (= (count params) 2) (apply (fn [p1 p2] (new ConnectionConfiguration p1 p2)) params) (= (count params) 3) (apply (fn [p1 p2 p3] (new ConnectionConfiguration p1 p2 p3)) params) (= (count params) 4) (apply (fn [p1 p2 p3 p4] (new ConnectionConfiguration p1 p2 p3 p4)) params)) ;; without apply (cond (= (count params) 2) (ConnectionConfiguration. (nth params 0) (nth params 1)) (= (count params) 3) (ConnectionConfiguration. (nth params 0) (nth params 1) (nth params 2)) (= (count params) 4) (ConnectionConfiguration. (nth params 0) (nth params 1) (nth params 2) (nth params 3))) Thanks again. - Mark On Wed, Jun 2, 2010 at 7:34 AM, Meikel Brandmeyer <m...@kotka.de> wrote: > Hi, > > On Jun 2, 2:51 am, Mark Rathwell <mark.rathw...@gmail.com> wrote: > > > ;; can do it with eval, but what is the correct way? > > user=> (eval `(ConnectionConfiguration. ~...@params)) > > (eval `(ConnectionConfiguration. ~...@params)) > > #<ConnectionConfiguration > > org.jivesoftware.smack.connectionconfigurat...@a0430b6> > > The best way is to use reflection. > > Calls to a constructor are hard-wired in the JVM bytecode, AFAIU. So > you have to know the arguments. If you *don't* know the arguments at > compile time, you have to lookup and call the correct constructor at > runtime via reflection. > > Sincerely > Meikel > > -- > 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<clojure%2bunsubscr...@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 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