JNI: global reference to a jarray in C++

  c++, java, java-native-interface

I’m writing a java program which makes extensive use of native methods and JNI implemented in C++. On the C++ side, I have a local reference to a jarray which I would like to convert to a global reference. Simple, I think: call env->NewGlobalRef(array_ref). And, indeed, this works — but the result is a jobject, not a jarray. Is it safe to downcast this back to a jarray? If not, can I recover a jarray from it? Note that I’m in C++, where these are not just typedefs of each other.

Source: Windows Questions C++