From: Updike, C. <Cla...@jh...> - 2004-02-03 14:31:55
|
I'm guessing java array types are all constructed dynamically in the JVM since there can be an arbitrary number of dimensions-- meaning that you'll have to do the Class.forName approach in jython since you can't do the int[] sytax as in java: >>> from java.lang import Class >>> Class.forName("[Ljava.lang.Integer;") <jclass [Ljava.lang.Integer; at 6909987> >>> # Here's one with four dimensions >>> Class.forName("[[[[Ljava.lang.Integer;") <jclass [[[[Ljava.lang.Integer; at 2645268> And you can create array instances (primitive or non-primitive) using java.lang.reflect.Array (or just use jarray): >>> from java.lang.reflect import Array >>> from java.lang import Integer >>> intArray = Array.newInstance(Integer.TYPE, 1) >>> intArray.__class__ <jclass org.python.core.PyArray at 1590779> >>> intArray array([0], int) >>> intArray2D = Array.newInstance(Integer.TYPE, [2,2]) >>> intArray2D array([array([0, 0], int), array([0, 0], int)], [I) -Clark -----Original Message----- From: Nicola de Candussio Sent: Tuesday, February 03, 2004 7:35 AM Subject: Re: SV: SV: [Jython-users] Array class instances So it has to be java-centric: strArrayClassName = "[Ljava.lang.Integer;" myClas = Class.forName( strArrayClassName ) as for example. No jython sugar about it .... Nicola |
From: Nicola de C. <nde...@rs...> - 2004-02-03 14:46:54
|
I guess so as well but it is possible to delegate it to the compiler by writing : Class c = Integer[].class or even Class c = Integer[][].class although I have never seen any tutorial or code documenting it ..... Updike, Clark wrote: >I'm guessing java array types are all constructed dynamically >in the JVM since there can be an arbitrary number of dimensions-- >meaning that you'll have to do the Class.forName approach in jython >since you can't do the int[] sytax as in java: > > > >>>>from java.lang import Class >>>>Class.forName("[Ljava.lang.Integer;") >>>> >>>> ><jclass [Ljava.lang.Integer; at 6909987> > > >>>># Here's one with four dimensions >>>>Class.forName("[[[[Ljava.lang.Integer;") >>>> >>>> ><jclass [[[[Ljava.lang.Integer; at 2645268> > >And you can create array instances (primitive or non-primitive) >using java.lang.reflect.Array (or just use jarray): > > > >>>>from java.lang.reflect import Array >>>>from java.lang import Integer >>>>intArray = Array.newInstance(Integer.TYPE, 1) >>>>intArray.__class__ >>>> >>>> ><jclass org.python.core.PyArray at 1590779> > > >>>>intArray >>>> >>>> >array([0], int) > > >>>>intArray2D = Array.newInstance(Integer.TYPE, [2,2]) >>>>intArray2D >>>> >>>> >array([array([0, 0], int), array([0, 0], int)], [I) > >-Clark > >-----Original Message----- >From: Nicola de Candussio >Sent: Tuesday, February 03, 2004 7:35 AM >Subject: Re: SV: SV: [Jython-users] Array class instances > > >So it has to be java-centric: > >strArrayClassName = "[Ljava.lang.Integer;" >myClas = Class.forName( strArrayClassName ) > >as for example. > >No jython sugar about it .... > >Nicola > > -- Nicola de Candussio Location: Dd019, Estec/SCI-SDH Internal extension: 56264 External Phone Number : +31 71 565 6264 www.estec.esa.nl |
From: Todd M. <tm...@in...> - 2004-02-03 20:16:54
|
Perhaps I'm not understanding the problem correctly, but this looks like it's getting more complicated than is necessary. Since Jython is so good at doing lists, why not create a jython list of java instances? This example is from an experiment I did on mixing java and jython: # from MyPak.MyGroupJy import MyGroupJy as MyGroup # all jython # from MyPak.MyGroupJyHy import MyGroupJyHy as MyGroup # some java from MyPak import MyGroup as MyGroup # mostly java # Create the specified number of groups. groups = [] for i in range(5): groups.append (MyGroup()) I've also seen jython convert java collections like vectors to lists transparently, though I don't have any examples handy. Cheers, Todd Moyer Nicola de Candussio wrote: > I guess so as well > but it is possible to delegate it to the compiler by writing : > > Class c = Integer[].class > > or even > > Class c = Integer[][].class > > although I have never seen any tutorial or code documenting it ..... > > Updike, Clark wrote: > >> I'm guessing java array types are all constructed dynamically >> in the JVM since there can be an arbitrary number of dimensions-- >> meaning that you'll have to do the Class.forName approach in jython >> since you can't do the int[] sytax as in java: >> >> >> >>>>> from java.lang import Class >>>>> Class.forName("[Ljava.lang.Integer;") >>>>> >> >> <jclass [Ljava.lang.Integer; at 6909987> >> >> >>>>> # Here's one with four dimensions >>>>> Class.forName("[[[[Ljava.lang.Integer;") >>>>> >> >> <jclass [[[[Ljava.lang.Integer; at 2645268> >> >> And you can create array instances (primitive or non-primitive) >> using java.lang.reflect.Array (or just use jarray): >> >> >> >>>>> from java.lang.reflect import Array >>>>> from java.lang import Integer >>>>> intArray = Array.newInstance(Integer.TYPE, 1) >>>>> intArray.__class__ >>>>> >> >> <jclass org.python.core.PyArray at 1590779> >> >> >>>>> intArray >>>>> >> >> array([0], int) >> >> >>>>> intArray2D = Array.newInstance(Integer.TYPE, [2,2]) >>>>> intArray2D >>>>> >> >> array([array([0, 0], int), array([0, 0], int)], [I) >> >> -Clark >> >> -----Original Message----- >> From: Nicola de Candussio Sent: Tuesday, February 03, 2004 7:35 AM >> Subject: Re: SV: SV: [Jython-users] Array class instances >> >> >> So it has to be java-centric: >> strArrayClassName = "[Ljava.lang.Integer;" >> myClas = Class.forName( strArrayClassName ) >> >> as for example. >> >> No jython sugar about it .... >> >> Nicola >> >> > |