Implementing interfaces with jpype

Hi there,

I’m struggling to implement an interface which has multiple methods with the same name but different signatures. Typically ParameterDriversProvider is like this, with getParameters which can take either no arguments, or one, or two. I’ve tried this:

    @JOverride()
    def getParameters(self):
        return []

    @JOverride()
    def getParameters(self, a):
        return []

    @JOverride()
    def getParameters(self, a, b):
        return []

but I get the following (trying to run a propagation, with a custom ForceModel which inherits from this interface):

TypeError: CustomForce.getParameters() missing 1 required positional argument: 'b'

Cheers,
Romain

Hi Romain,

Can you provide a minimum working example?

Did you maybe try with @JOverride instead of @JOverride()?

Ok so the problem seemed to be that I was calling one of these methods and I think python didn’t know which one to pick. I’ll let you know if I come into more trouble.

Cheers

Hi Serrof,

Yes, jpype don’t do method resolution for implemented interfaces (python has no concept of same method name with different parameters), so one needs to do this oneself. JPype User Guide — JPype 1.6.0.dev0 documentation

This can be done with the new python 3.12(?) match statement.

See discussion in Plan for new way of multiple dispatch in orekit python wrapper

1 Like