How can we new primitive types in JNI. I have a function that returns a jobject. It is possible to return jint, jchar, etc.
There is NewString, why not NewInteger, NewCharacter, NewDouble, etc. There is no autoboxing at JNI layer at the moment.
I can go with the NewObject call, but this will be too much overhead to create primitive types.
jobject NewInteger(JNIEnv* env, jint value)
{
jclass cls = FindClass(env, "java/lang/Integer");
jmethodID methodID = GetMethodID(env, cls, "<init>", "(I)V", false);
return env->NewObject(cls, methodID, value);
}
I have wrapper functions to get Class and MethodID.