JNI interface pointer confusion
I keep seeing the env
interface pointer used with and without dereferencing, for example
env->DoSomething(arguments)
vs.
(*env)->DoSomething(en开发者_开发问答v, arguments)
Are they actually different things? Is one from an older JNI implementation?
They're the same thing; just a little macro magic. The nicer (first) syntax is enabled in a C++ context.
It's the difference between writing jni code in C and C++, from wikipedia:
Note that C++ JNI code is syntactically slightly cleaner than C JNI code because like Java, C++ uses object method invocation semantics. That means that in C, the env parameter is dereferenced using (*env)-> and env has to be explicitly passed to JNIEnv methods. In C++, the env parameter is dereferenced using env-> and the env parameter is implicitly passed as part of the object method invocation semantics.
精彩评论