Sorry, that's true. newInstance doesn't take arguments.

For what it's worth, looking up the correct constructor can be a
tricky business.  If you already know exactly which constructor you
want, it's no big deal.  On the other hand, if you want to write a
general function that takes a class object and a set of argument
classes, that's a little harder.

On Jan 12, 3:03 am, Shantanu Kumar <kumar.shant...@gmail.com> wrote:
> On Jan 12, 12:50 pm, Konrad Hinsen <konrad.hin...@fastmail.net> wrote:
>
> > On 11 Jan 2010, at 23:09, .Bill Smith wrote:
>
> > > Every class object has a newInstance method:
>
> > > user=> (Class/forName "java.util.HashMap")
> > > java.util.HashMap
> > > user=> (.newInstance (Class/forName "java.util.HashMap"))
> > > #<HashMap {}>
> > > user=>
>
> > > Is that what you are looking for?
>
> > It seems close, but it doesn't work for me. From experimenting I have  
> > the impression that this works only for constructors with no arguments.
>
> The Class object can give you the exact constructor object (with
> argument foo):
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#getConst......)
>
> and then you can call the newInstance(fooObject) method on the
> constructor object to create object with parameter foo.
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Constructor......)
>
> HTH
>
> Regards,
> Shantanu
-- 
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