Calling Scala Companion Object

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling Scala Companion Object

Surendranauth Hiraman
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
F: 646.349.4063
E: [hidden email]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 awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Calling Scala Companion Object

Jeff Emanuel

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
F: 646.349.4063
E: [hidden email]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 awards
http://p.sf.net/sfu/Bonitasoft


_______________________________________________
Jython-users mailing list
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Calling Scala Companion Object

Surendranauth Hiraman
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 <[hidden email]> 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: <a href="tel:%28917%29%20525-2466%20ext.%20105" value="+19175252466" target="_blank">(917) 525-2466 ext. 105
F: <a href="tel:646.349.4063" value="+16463494063" target="_blank">646.349.4063
E: [hidden email]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 awards
http://p.sf.net/sfu/Bonitasoft


_______________________________________________
Jython-users mailing list
[hidden email]
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
[hidden email]
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
F: 646.349.4063
E: [hidden email]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 awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Calling Scala Companion Object

Surendranauth Hiraman
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 <[hidden email]> 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 <[hidden email]> 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: <a href="tel:%28917%29%20525-2466%20ext.%20105" value="+19175252466" target="_blank">(917) 525-2466 ext. 105
F: <a href="tel:646.349.4063" value="+16463494063" target="_blank">646.349.4063
E: [hidden email]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 awards
http://p.sf.net/sfu/Bonitasoft


_______________________________________________
Jython-users mailing list
[hidden email]
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
[hidden email]
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: <a href="tel:%28917%29%20525-2466%20ext.%20105" value="+19175252466" target="_blank">(917) 525-2466 ext. 105
F: <a href="tel:646.349.4063" value="+16463494063" target="_blank">646.349.4063
E: [hidden email]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: [hidden email]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 awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Calling Scala Companion Object

Jeff Emanuel
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 <[hidden email]> 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 <[hidden email]> 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: <a moz-do-not-send="true" href="tel:%28917%29%20525-2466%20ext.%20105" value="+19175252466" target="_blank">(917) 525-2466 ext. 105
F: <a moz-do-not-send="true" href="tel:646.349.4063" value="+16463494063" target="_blank">646.349.4063
E: [hidden email]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 awards
http://p.sf.net/sfu/Bonitasoft


_______________________________________________
Jython-users mailing list
[hidden email]
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
[hidden email]
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: <a moz-do-not-send="true" href="tel:%28917%29%20525-2466%20ext.%20105" value="+19175252466" target="_blank">(917) 525-2466 ext. 105
F: <a moz-do-not-send="true" href="tel:646.349.4063" value="+16463494063" target="_blank">646.349.4063
E: [hidden email]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: [hidden email]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 awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Calling Scala Companion Object

Surendranauth Hiraman
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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: <a href="tel:%28917%29%20525-2466%20ext.%20105" value="+19175252466" target="_blank">(917) 525-2466 ext. 105
F: <a href="tel:646.349.4063" value="+16463494063" target="_blank">646.349.4063
E: [hidden email]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 awards
http://p.sf.net/sfu/Bonitasoft


_______________________________________________
Jython-users mailing list
[hidden email]
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
[hidden email]
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: <a href="tel:%28917%29%20525-2466%20ext.%20105" value="+19175252466" target="_blank">(917) 525-2466 ext. 105
F: <a href="tel:646.349.4063" value="+16463494063" target="_blank">646.349.4063
E: [hidden email]elos.io
W: www.velos.io




--
                                                            
SUREN HIRAMAN, VP TECHNOLOGY
Velos
Accelerating Machine Learning

440 NINTH AVENUE, 11TH FLOOR
NEW YORK, NY 10001
O: <a href="tel:%28917%29%20525-2466%20ext.%20105" value="+19175252466" target="_blank">(917) 525-2466 ext. 105
F: <a href="tel:646.349.4063" value="+16463494063" target="_blank">646.349.4063
E: [hidden email]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: [hidden email]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 awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users