举例来说,考虑相同方法的两个版本,如清单 4 所示:
清单 4. 相同方法的两个版本
- jlong getElement(JNIEnv* env, jobject obj, jlongArray arr_j,
- int element){
- jboolean isCopy;
- jlong result;
- jlong* buffer_j = (*env)->GetLongArrayElements(env, arr_j, &isCopy);
- result = buffer_j[element];
- (*env)->ReleaseLongArrayElements(env, arr_j, buffer_j, 0);
- return result;
- }
- jlong getElement2(JNIEnv* env, jobject obj, jlongArray arr_j,
- int element){
- jlong result;
- (*env)->GetLongArrayRegion(env, arr_j, element,1, &result);
- return result;
- }
- }