So after thinking about Alex and James' respective answers I think the
full answer to your question is that no you can't do that for reasons
pretty fundamental to the JVM unless you care to constrain the problem
domain or qualify your question some more.
Making a new class instance is a three step
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 wrote:
> Is there a way to parameterize a bit of code that invokes a constructor
> withou
Use a macro to produce the right code...
--
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 unsubsc
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