Hi,
Is it possible to call a native CPP function using JNI which takes generic arguments? Something like the following:
public static native <T, U, V> T foo(U u, V v);
And then call it like:
//class Foo, class Bar, class Baz are already defined;
Foo f = foo(new Bar(), new Baz());
Can anyone please provide me with a sample which is actually doing this or some tutorial on the net which does this? I am asking because in my CPP JNI function (called by JVM), I get unsatisfied link error.
CPP Code follows:
JNIEXPORT jobject JNICALL Java_Processor_process (JNIEnv *env, jclass processor_class, jobject obj1, jobject obj2)
{
jclass bar_class = env->FindClass("Bar");
jmethodID getFooMethod = env->GetMethodID(bar_class, "getFoo", "()Ljava/lang/Object;");
//getFoo() is defined as `public Foo getFoo();` in Bar.java
return env->CallObjectMethod(obj1, getFooMethod);
}
EDIT:
I have tried by modifying the code but now I am getting NoSuchMethodError:
Java code:
public static native <U, V> String foo(U u, V v);
//...
String str = foo(new Bar(), new Baz());
CPP code:
JNIEXPORT jstring JNICALL Java_Processor_process (JNIEnv *env, jclass processor_class, jobject obj1, jobject obj2)
{
jclass bar_class = env->FindClass("Bar");
jmethodID getFooMethod = env->GetMethodID(bar_class, "getFoo", "()Ljava/lang/String;");
//getFoo() is now defined as `public String getFoo();` in Bar.java
return env->CallObjectMethod(obj1, getFooMethod);
}
Does this mean that JNI has no support for generics or am I missing something?