将 JNI 类型转换为 Native 类型 [英] Convert JNI types to Native types
问题描述
虽然有关于将 jstring
转换为本机字符串的文档 (string nativeString = env->GetStringUTFChars(jStringVariable, NULL);
) 我找不到将 jboolean
转换为 bool
或 jint
转换为 int
的示例.
While there is documentation regarding turning a jstring
to a native string (string nativeString = env->GetStringUTFChars(jStringVariable, NULL);
) I can't find an example which will convert a jboolean
to a bool
or a jint
to an int
.
谁能建议这是如何实现的?
Can anyone suggest how this is achieved?
推荐答案
你只需要使用 C 风格转换将 jint
转换为 int
.jboolean
到 bool
(如果您使用 C99 bool
类型)或 uint8_t
(如果您使用重新使用 std int 类型)或 unsigned char
.
You just need to cast jint
to int
using C style casts. Same for jboolean
to bool
(if you're using C99 bool
type) or to uint8_t
(if you're using std int types) or to unsigned char
.
打开 $NDK_ROOT/platforms/android-8/arch-arm/usr/include/jni.h
你会看到 jint
, jboolean
等只是 typedef
s.
Open $NDK_ROOT/platforms/android-8/arch-arm/usr/include/jni.h
and you'll see jint
, jboolean
etc are just typedef
s.
这篇关于将 JNI 类型转换为 Native 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!