将 JNI 类型转换为 Native 类型 [英] Convert JNI types to Native types

查看:33
本文介绍了将 JNI 类型转换为 Native 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然有关于将 jstring 转换为本机字符串的文档 (string nativeString = env->GetStringUTFChars(jStringVariable, NULL);) 我找不到将 jboolean 转换为 booljint 转换为 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.jbooleanbool (如果您使用 C99 bool 类型)或 uint8_t (如果您使用重新使用 std int 类型)或 unsigned char.

You just need to cast jintto 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 等只是 typedefs.

Open $NDK_ROOT/platforms/android-8/arch-arm/usr/include/jni.h and you'll see jint, jboolean etc are just typedefs.

这篇关于将 JNI 类型转换为 Native 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆