Thursday, April 05, 2007

Undocumented Jython — Java callable Jython class idiom

You have to do

from java import lang
class Backplane(lang.Object):
def performSetup(self, arg):
"@sig public void performSetup(java.lang.String arg)"
...
view raw gistfile1.py hosted with ❤ by GitHub


and not

import java
import java.lang
class Backplane(java.lang.Object):
def performSetup(self, arg):
"@sig public void performSetup(java.lang.String arg)"
...
view raw gistfile1.py hosted with ❤ by GitHub


in order to make jythonc generate the function calls you want in the intermediate Java code.

And as I'm in a “Jython calls Java calls Jython” state, doing some transcoding/refactoring, I have still not managed to get Jython at the front to call nicely into the Jython at the back.

import myPackage
obj = myPackage.Backplane()
print obj.getArg0
print obj.getArg0()
view raw gistfile1.py hosted with ❤ by GitHub


causes

method myPackage.Backplane.performSetup of myPackage.Backplane instance 1
Traceback (innermost last):
  ...
AttributeError: abstract method "performSetup" not implemented

despite it being there quite plain as day:-

public void performSetup(java.lang.String arg) {
...
}
view raw gistfile1.java hosted with ❤ by GitHub


and despite Java code calling it quite happily.

*sigh*

2 comments :

Anonymous said...

“Jython calls Java calls Jython”

Why? Stick to one language unless you are going for modern version of the obfuscated C competition!

Steve Gilham said...

Why -- to port some existing code from Java into Python, with the Jython environment as a medium for doing testable, stepwise replacement, and replacing one module at a time; rather than launching into a big-bang, recoding everything and then testing at the end.

There is usually method in some apparent madness.