Hi Andy,

Thanks for your email, it answers my questions. I am doing a bunch of java
classes with extension points, and as it is sometimes hard to judge if a
default method may be needed as extension point in some scenario, I am
rather tending towards putting an extension point and let the user of the
library run the default code if they don't want to implement it (by
accessing the interface method direclty).

Best Regards
/Petrus




On Sat, Jan 19, 2019 at 11:56 PM Andi Vajda <va...@apache.org> wrote:

>
>   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
> >



-- 
_____________________________________________
Petrus Hyvönen, Uppsala, Sweden
Mobile Phone/SMS:+46 73 803 19 00

Reply via email to