From: Surendranauth H. <sur...@ve...> - 2014-07-09 19:12:44
|
Apologies but I realize my mistake. The method is not static. This is because the companion object in Scala is a Singleton, not a static method holder. The singleton instance is referenced by a public static final member of the class, though, so I should be able to get to it in some way. The only issue is that this member (named 'MODULE$') also has the '$' character in its name. But as you've guided me, reflection should allow me to access it. Unless you can think of another way to get to it in Jython. Thanks for your help! -Suren On Wed, Jul 9, 2014 at 1:56 PM, Jeff Emanuel <jem...@fr...> wrote: > You should be able to call static methods on the class object. Try > > print companionObj.findAll.argslist > > That will tell you what argument you are missing or whether the method is > truly static. > > > > > On 7/9/2014 11:52 AM, Surendranauth Hiraman wrote: > > Sorry Jeff, please ignore. I realized that that code just gives me a Class > object. I then have to use reflection or another approach to access the > method I need, I think. > > Thanks for your help! > > -Suren > > > > On Wed, Jul 9, 2014 at 1:46 PM, Surendranauth Hiraman < > sur...@ve...> wrote: > >> Elegant in its simplicity. I'm smacking my head. :-) >> >> I tried it and I get the following error, I think because the method on >> the companion object is a static method? >> >> >>> companionObj = Class.forName("com.mystuff.ProjectDAO$") >> >> >>> companionObj.findAll() >> >> Traceback (most recent call last): >> >> File "<stdin>", line 1, in <module> >> >> TypeError: findAll(): expected 1 args; got 0 >> >> >>> companionObj.findAll >> >> <java function findAll 0x5> >> >> >> >> >> >> On Wed, Jul 9, 2014 at 1:31 PM, Jeff Emanuel <jem...@fr...> wrote: >> >>> >>> How about calling java.lang.Class.forName to get the class? >>> >>> theCompanionClass = java.lang.Class.forName("whatever$"); >>> theCompanionClass.doSomething() >>> >>> >>> >>> On 7/9/2014 10:42 AM, Surendranauth Hiraman wrote: >>> >>> Anyone have any experience calling a Scala companion object from >>> Jython? >>> >>> I have no problem calling a Scala class. >>> >>> But because companion objects (holders for static methods) are >>> actually a separate generated class with the '$' character at the end of >>> the name, I'm having trouble accessing/importing them. >>> >>> I guess the general problem would be how to access a class with the >>> '$' in its name. >>> >>> I wanted to confirm with folks more knowledgeable than me whether this >>> can be done. >>> >>> Thanks! >>> >>> >>> SUREN HIRAMAN, VP TECHNOLOGY >>> Velos >>> Accelerating Machine Learning >>> >>> 440 NINTH AVENUE, 11TH FLOOR >>> NEW YORK, NY 10001 >>> O: (917) 525-2466 ext. 105 <%28917%29%20525-2466%20ext.%20105> >>> F: 646.349.4063 >>> E: suren.hiraman@v <sur...@so...>elos.io >>> W: www.velos.io >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> Open source business process management suite built on Java and Eclipse >>> Turn processes into business applications with Bonita BPM Community Edition >>> Quickly connect people, data, and systems into organized workflows >>> Winner of BOSSIE, CODIE, OW2 and Gartner awardshttp://p.sf.net/sfu/Bonitasoft >>> >>> >>> >>> _______________________________________________ >>> Jython-users mailing lis...@li...https://lists.sourceforge.net/lists/listinfo/jython-users >>> >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> Open source business process management suite built on Java and Eclipse >>> Turn processes into business applications with Bonita BPM Community >>> Edition >>> Quickly connect people, data, and systems into organized workflows >>> Winner of BOSSIE, CODIE, OW2 and Gartner awards >>> http://p.sf.net/sfu/Bonitasoft >>> _______________________________________________ >>> Jython-users mailing list >>> Jyt...@li... >>> https://lists.sourceforge.net/lists/listinfo/jython-users >>> >>> >> >> >> -- >> >> SUREN HIRAMAN, VP TECHNOLOGY >> Velos >> Accelerating Machine Learning >> >> 440 NINTH AVENUE, 11TH FLOOR >> NEW YORK, NY 10001 >> O: (917) 525-2466 ext. 105 <%28917%29%20525-2466%20ext.%20105> >> F: 646.349.4063 >> E: suren.hiraman@v <sur...@so...>elos.io >> W: www.velos.io >> >> > > > -- > > SUREN HIRAMAN, VP TECHNOLOGY > Velos > Accelerating Machine Learning > > 440 NINTH AVENUE, 11TH FLOOR > NEW YORK, NY 10001 > O: (917) 525-2466 ext. 105 > F: 646.349.4063 > E: suren.hiraman@v <sur...@so...>elos.io > W: www.velos.io > > > -- SUREN HIRAMAN, VP TECHNOLOGY Velos Accelerating Machine Learning 440 NINTH AVENUE, 11TH FLOOR NEW YORK, NY 10001 O: (917) 525-2466 ext. 105 F: 646.349.4063 E: suren.hiraman@v <sur...@so...>elos.io W: www.velos.io |