On Apr 3, 5:53 am, JonathanBelolo <[email protected]> wrote:
> Ok, so here's the thing:
>
> I'd like to keep a reference to a class somewhere, and later retrieve
> it to instantiate.
> But references to classes don't seem to be valid arguments to the new
> special function.
>
> For ex,
>
> (let [the-class java.lang.String]
>  (new the-class))
>
> this throws an error (at least, in 1.2) : Unable to resolve classname:
> the-class
>
> After fiddling around, I found this ugly hack :
>
> (let [the-class java.lang.String]
>  (eval `(new ~the-class)))
>
> Am I missing something?

Instead of storing the class, consider storing a factory function for
later re-use.

(def foo #(java.lang.String.))

The other technique is to instantiate the class using reflection but
that may be slower.

Regards,
Shantanu

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

Reply via email to