On Dec 3, 6:15 am, lazy1 <miki.teb...@gmail.com> wrote:
> Hello,
>
> I'm trying to create a "factory" method for Java classes, however I'm
> doing something wrong.
>
> (import '(java.util Dictionary HashMap))
>
> (def *containers* { :dict Dictionary :hash HashMap})
> (defn new-container
>   [type]
>   (new (*containers* type)))
>
> (def d (new-container :dict))
<snip>

> What is the right way to do this?

As others have stated, you can't use new, but since you're storing
Class objects in a hashmap, you could simply call (.newInstance
(*containers* type))... of course, assuming that the Class is
instantiable.

--
Jarkko

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

Reply via email to