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