It is fixed in originell's jpype fork https://github.com/originell/jpype/commit/0e6067f2eec78f6c697b3714f467142fa9b58243
JPype's properties access shadows method with property name
Question
How can I access a Java method named next()
when the same class has a getNext()
method?
JPype has the feature to give you access to bean properties (get-Methods without a parameter) using just the property name. So if you have a class with a method getNext()
you can access that bean property from within python using instance.next
which is nice in 99,9% of the cases. But how can I access the instance.next()
? If I call instance.next()
I'll get an exception saying that the return type of the bean property is not callable.
Solution 2
OTHER TIPS
You'll probably have to resort to using reflection on the underlying java class:
# iterate through all methods
for method in instance.__javaclass__.getMethods():
# find the method matching the correct signature
if method.name == u'next' and len(method.parameterTypes) == 0:
# create a function that invokes the method on the given object
# without additional arguments
next_instance = lambda o: method.invoke(o, [])
break
else:
raise Exception('method was not found')
nxt = next_instance(instance)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow