0

I have code that is implementing an observer pattern in C++. I have created Java JNI code that is similar to C++ code to register an observer. When I register an observer in Java, it calls a native method that create a listener in C++.

I want the method calls in C++ to call the equivalent methods in my Java observer that is registered. I have created code for this by passing the JNIEnv to the observer class in C++, but I've heard this isn't safe. Is there a best practice on this type of implementation?

1 Answer 1

0

You can use SWIG directors per the answer to this question: How to pass java function pointer to c++ native code

I would also recommend using SWIG instead of JNI directly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.