Re: Creating an object given a class object

2010-01-16 Thread Konrad Hinsen
On 16.01.2010, at 15:22, Rich Hickey wrote: Since Clojure already does this, you can borrow its implementation, found in clojure.lang.Reflector. In this case, see invokeConstructor. (clojure.lang.Reflector/invokeConstructor (class (ref "foo")) (to- array [42])) Great, thanks, this simplifies

Re: Creating an object given a class object

2010-01-16 Thread Rich Hickey
On Tue, Jan 12, 2010 at 2:50 AM, Konrad Hinsen 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")) >> # >> user=> >

Re: Creating an object given a class object

2010-01-14 Thread evins.mi...@gmail.com
On Jan 12, 1:50 am, Konrad Hinsen 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")) > > # > > user=> > > > I

Re: Creating an object given a class object

2010-01-12 Thread .Bill Smith
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

Re: Creating an object given a class object

2010-01-12 Thread Shantanu Kumar
On Jan 12, 12:50 pm, Konrad Hinsen 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")) > > # > > user=> > > >

Re: Creating an object given a class object

2010-01-11 Thread Konrad Hinsen
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")) # user=> Is that what you are looking for? It seems close, but it doesn't work for

Re: Creating an object given a class object

2010-01-11 Thread .Bill Smith
Every class object has a newInstance method: user=> (Class/forName "java.util.HashMap") java.util.HashMap user=> (.newInstance (Class/forName "java.util.HashMap")) # user=> Is that what you are looking for? On Jan 11, 4:03 pm, Konrad Hinsen wrote: > Is there a way to create a new object by call

Creating an object given a class object

2010-01-11 Thread Konrad Hinsen
Is there a way to create a new object by calling its java constructor given just the class object? The new form doesn't do the job, as it requires a symbol naming the class. But I can't find anything else on the Java interop page... Is this impossible? Konrad. -- You received this message