You'll need to with with the Constructor object returned from
Class.getConstructor(Class...).

Or use this:

(defn new-instance [#^Class c & args]
  (if args
    (.newInstance
      (.getConstructor c (into-array Class (map class args)))
      (into-array Object args))
    (.newInstance c)))

On Mar 26, 12:51 pm, Miki <[email protected]> wrote:
> Hello,
>
> I'm trying the newInstance examples 
> fromhttp://en.wikibooks.org/wiki/Learning_Clojure,
> however I get an error:
>
> Clojure 1.1.0
> user=> (new String "")
> ""
> user=> (. (identity String) newInstance "")
> java.lang.IllegalArgumentException: No matching method found:
> newInstance for class java.lang.Class (NO_SOURCE_FILE:0)
> user=> (.newInstance String "")
> java.lang.IllegalArgumentException: No matching method found:
> newInstance for class java.lang.Class (NO_SOURCE_FILE:0)
> user=> (.newInstance (identity String) "")
> java.lang.IllegalArgumentException: No matching method found:
> newInstance for class java.lang.Class (NO_SOURCE_FILE:0)
> user=>
>
> I can't use the "new" macro since I store several classes in a hash
> and pick the one I want in runtime (factory like).
>
> newInstance with no argument work though:
> user=> (.newInstance String)
> ""
> user=>
>
> Any ideas?
>
> Thanks,
> --
> Miki

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to