I’ve got the following setup with a base class storing a pointer eventually set from JNI
class Struct {
private long ptr;
long c_ptr() { return ptr; }
}
class NativeInterface {
static native void somefunc(Struct st);
...
}
Then a particular Struct that will be passed to NativeInterface:somefunc that needs to be able to access it’s ptr field. My question is how to pass the super of SomeStruct to the native interface? Should it be like this or with a cast?
class SomeStruct extends Struct {
void somefunc() {
NativeInterface.somefunc(super);
}
}
Just do the usual steps: get a field ID via JNI introspection on the Struct class, then get/set its value providing the SomeStruct instance as the object argument.