I’m using SWIG to export a c++ class to Java, but ran into a problem trying to force the proxy object to implement an interface.
I scoured the SWIG documentation and found you could use “%pragma(java) jniclassinterfaces=x” to have the JNI class implement a given interface, and use “%pragma(java) moduleinterfaces=x” to have the module implement any given interface, but no corresponding pragma for the actual proxy object.
I would prefer having SWIG generate the ‘implements X’ code, as trying to add that implementation later on is proving difficult. For example, if I try to subclass the SWIG proxy and then implement the interface, I run into issues because I’m also using generics:
interface IVector<VectorType> {
VectorType add(VectorType other);
...
}
So something like this fails:
class MyVector extends MyProxyVector implements IVector<MyVector> {
MyVector add(MyVector other) {
return (MyVector) super.add(other);
}
}
because it would require casting a parent to a child class.
The only other ways I can come up with getting around this problem is to either create a wrapper class or use a copy constructor. Both seem somewhat inefficient as their entire purpose to to implement the one interface.
This should be handled via the typemaps mechanism.
The following code:
Sets the bases and interfaces for
Foo, like so:in the generated Java proxy class.