Hi Petrus,
On Sat, 19 Jan 2019, Petrus Hyvönen wrote:
I am working on wrapping a number of (java) interfaces as python classes
(through JCC).
Typically I have an "Interface" and make a class "PythonInterface", where I
take the methods and make public nativec mehtods of them. In some cases my
Interfaces has methods of same name but different parameters. What are the
best way to implement this, how does JCC behave in those cases, would both
"point" to the same python function. The alternative I have is to make
separate native functions and somehow separate the names of the similar
methods. Le me know if you have some expeience.
To "implement" a Java interface from Python you first need an extension
point Java class that actually implements this interface.
For example, see java/org/apache/pylucene/util/PythonComparable.java
in the PyLucene sources.
It works just like a Java class you wish to "extend" from Python, you first
need an extension point Java class that actually extends the class.
If you have overloads of Java methods (ie, methods with the same name but
different parameters) you should provide Java implementations that call a
different native method, with a particular name, for each overload
signature. For example, the remove() method in
java/org/apache/pylucene/util/PythonList.java defines two native methods,
removeAt(int) and removeObject(Object) that are called by Java
implementations (or overrides) of the remove(int) and remove(Object)
methods defined on java.util.List, respectively.
My second questions is on default implementation in interfaces. Some of the
default methods in the interface are unlikely to be needed to reimplement.
I have so far however put all methods as public native in the wrapping
class. It seems like it is possible to call the default code from python by
calling the interface directly "Interface.method(self, param)" and reducing
the effort needed on the python side. Any thoughts on this?
Interface default methods are like static methods on Java classes, they
should get wrapped by JCC just the same. If you have no reason to override
them from Python, don't add a native "implementation".
Andi..
Thankful for any feedback,
Regards
/Petrus
--
_____________________________________________
Petrus Hyvönen, Uppsala, Sweden
Mobile Phone/SMS:+46 73 803 19 00