On Sun, May 25, 2014 at 2:00 PM, Shantanu Kumar <[email protected]> wrote: > > > On Sunday, 25 May 2014 22:45:27 UTC+5:30, Gregg Reynolds wrote: >> >> Hi, >> >> I'm trying to construct a Java obj from a from a classname string. >> I've managed to import the thing using a macro: >> >> (defmacro import-by-name [name] `(import [~name])) >> (let [klass-name "foo.bar.Baz" >> the-ns (import-by-name klass-name) >> the-obj (new foo.bar.Baz arg)] ...) >> .... >> >> But when I use a string instead of literal arg to new I get "Unable to >> resolve classname": >> ... >> the-obj (eval `(new ~klass-name ~arg)) > > > Instead of ~klass-name, try ~(symbol klass-name) or ~(Class/forName > klass-name).
Many thanks. Class/forName works great. Thanks, gregg -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
