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).

HTH

Shantanu

-- 
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/d/optout.

Reply via email to