Hi,
On Dec 3, 4:46 pm, lazy1 wrote:
> >> What is the right way to do this?
> > (defn new-container
> > [type]
> > (.newInstance (*containers* type)))
> > (defmacro new-container [type]
> > `(new ~(*containers* type)))
>
> Thanks! These are both great and also very educational.
>
> The reason fo
Hello All,
>> What is the right way to do this?
> (defn new-container
> [type]
> (.newInstance (*containers* type)))
> (defmacro new-container [type]
> `(new ~(*containers* type)))
Thanks! These are both great and also very educational.
The reason for this coding style is that I'm writing a wr
On Dec 3, 4:15 am, lazy1 wrote:
> Hello,
> What is the right way to do this?
As people have mentioned, new is a special form which evaluates it's
arguments at
compile time and cannot be used with a dynamic class name.
Fortunately you can use the reflection API and create instance of your
class
On Dec 3, 6:15 am, lazy1 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
On Dec 2, 11:15 pm, lazy1 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 (*container
On Dec 2, 8:15 pm, lazy1 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
(new) tries to resolve the argument at compile-time, not runtime. You need
to spell out each (new class) in a cond. You might write a macro to make it
a little less verbose.
-Mike
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this grou
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))
The above gi