Noman Akhtar
Noman Akhtar

Reputation: 730

how to modify the value of a primitive data passed to a C++ routine using Java and JNI?

Can I pass a primitive from Java to my C++ function using JNI function calls and modify its value in the C++ function ?

So far, I have seen examples of returning jstring,jint,jboolean etc, which I do not want to do. The other option that I know about is to get the ID of the primitive variable within C++ and set its value.

For Example :

JNIEXPORT void JNICALL Java_myFunction
(JNIEnv *, jobject obj, jboolean retJava)

Here i am passing boolean from java and want to change it in C++ depending on my computation without return statement.

Upvotes: 0

Views: 69

Answers (1)

Steeve
Steeve

Reputation: 1341

Unfortunately you can not do this with JNI.

You can hack it with using boxed types (see an example here) but it is strongly discouraged, as it can break all kinds of things easily (as to what exactly, see the comments in the linked question).

Upvotes: 1

Related Questions