8장. long 데이터형 값 주고 받기
$ vi PassAndReturnLong.cpp#include <jni.h>
jlong factorial
(
JNIEnv *env,
jobject thiz,
jlong num
)
{
if(num <= 1) return 1L;
return num * factorial(env, thiz, num-1);
}
JNIEXPORT jint JNICALL JNI_OnLoad
(
JavaVM *vm,
void *reserved
)
{
JNIEnv *env;
if(vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6)) {
return -1;
}
JNINativeMethod nm {
const_cast<char *>("factorial"),
const_cast<char *>("(J)J"),
reinterpret_cast<void *>(factorial)
};
jclass cls = env->FindClass("Client");
env->RegisterNatives(cls, &nm, 1);
return JNI_VERSION_1_6;
}Last updated