Robert - It's a bit convoluted on how I get the callback executed. I have to fit into some legacy Java code, so it's not pretty.
On the Java side I have an interface
public interface SpecialPythonEvaluator {
void Evaluate(MyJavaClass sol);
}
And then there's a special class that inherits from the framework I'm using
public class SpecialPythonClass extends LegacyClass {
SpecialPythonEvaluator evaluator;
public SpecialPythonClass(SpecialPythonEvaluator evaluator) {
this.evaluator = evaluator;
}
public void Evaluate(MyJavaClass sol){
evaluator.Evaluate(sol);
}
}
On the Python side I have the python implementation of that interface
class PythonEvaluator(PythonJavaClass):
__javainterfaces__ = ['com/company/SpecialPythonEvaluator']
def __init__(self, Evaluate=None):
self.CBEvaluate = Evaluate
@java_method('(Lcom/company/MyJavaClass;)V')
def Evaluate(self, sol):
if (self.CBEvaluate is not None):
self.CBEvaluate(sol)
Then I construct the python class that implements the Java interface and pass it into my framework so that it gets called
myEvaluator=PythonEvaluator(Evaluate)
myMainObject=SpecialPythonClass(myEvaluator)
When the original (Java) LegacyClass calls it's Evaluate method, that gets overridden by (Java) SpecialPythonClass which has a handle to an interface (Java) SpecialPythonEvaluator.
There's a (Python) implementation of Python Evaluator that then forwards the call to a first-class (Python) function Evaluate.
It's not pretty, but it does work passing the right object around. I just need to handle a special branch for when sol is (Java) null. I have an idea of how to do it if pyjnius doesn't give me access to that, I was just hoping to make it pretty.
ElliotG -
For both of the null and not-null cases, I get this when I print my type
print('Type=',type(sol))