I have a base class defined in java. I would like to call a native method like so:
public class Base<T>
{
public void doSomething()
{
nativeDoSomething();
}
private native void nativeDoSomething();
}
My question is, how do I specify the jni method signature of a generic class?
I'm late here, but I'll add it for future references.
Generics in Java are implemented using Type Erasure, which basically is: generics exists only in compile-time: they are gone after that, not existing in run-time.
This means that, even though you can have a method like public native void blah(E genericOne, F genericTwo)
, when compiled, it is actually converted to public native void blah(Object genericOne, Object genericTwo)
.
This way, you don't need to even care about generics when using the Java Native Interface: everything is converted down to Object
, so you can simply reference them as a jobject
.
The same goes for the Java classes: you can simply reference them as a jclass
.
javah
seems to ignore generics:
JNIEXPORT void JNICALL Java_Base_nativeDoSomething
(JNIEnv *, jobject);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With