You could use eval:

(defn make-it [class]
  (eval `(new ~class "abc")))

That's likely to be less performant than using
java.lang.reflect.Constructor though.

- James

On 23 August 2015 at 21:06, Dave Tenny <dave.te...@gmail.com> wrote:

> Is there a way to parameterize a bit of code that invokes a constructor
> without calling the java.lang.reflect.Constructor class?
>
> e.g.
>
> (defn make-it [class]
>   (new class "abc")) ; won't work
>
> (make-it IllegalArgumentException)
>
> I was trying to parameterize the class of exception thrown in a bit of
> code in my case,
> but it appears the compiler wants a Class name and nothing else in java
> interop constructor positiosn.
>
>
> --
> 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.
>

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