On Dec 5, 2009, at 2:48 PM, Christopher Wicklein wrote: > Greetings!
Hello!
> I'd like to create an instance of a Java class like this:
>
> let [foo (Bar.)]
>
> but, I'd like the type specified by Bar to not be static, e.g. something like
> this:
>
> let [foo (:type params).]
>
> but, I can't seem to get this to work with any variation of syntax I've
> tried. Is this possible?
If you can arrange to have the class name as a string, you can use
clojure.contrib.core/new-by-name:
user=> (use '[clojure.contrib.core :only [new-by-name]])
nil
user=> (new-by-name "java.util.Date")
#<Date Sat Dec 05 16:57:12 EST 2009>
user=> (source new-by-name)
(defn new-by-name
"Constructs a Java object whose class is specified by a String."
[class-name & args]
(clojure.lang.Reflector/invokeConstructor
(clojure.lang.RT/classForName class-name)
(into-array Object args)))
nil
user=>
--Steve
(source is in clojure.contrib.repl-utils)
smime.p7s
Description: S/MIME cryptographic signature
