Calling Right Overload Of The Java Method From Jython
I am using java library, that has overloaded methods in the class that I use. JAVA: void f(float[]); void f(Object[]); Now I call this class from jython, and I want to call the Ob
Solution 1:
It took me considerable amount of time to find out, so I decided to post a question together with the answer.
Forcing the right overload
Jython documentation tells that in order to to force a call of right overload you should cast arguments to java objects manually before the call:
from java.lang import Byte
foo(Byte(10))
However that doesn't work with java arrays.
Forcing the right overload for array
http://www.jython.org/archive/22/userguide.html#java-arrays
It's possible to create java arrays in jython. For example the following code will create in jython java array of type int[]
from jarray import array
array(python_array, 'i')
You can create Object[] like this, and force java to call the right overload.
from jarray import array
from java.lang import Object
oa = array(python_array, Object)
f(oa)
Post a Comment for "Calling Right Overload Of The Java Method From Jython"