简体   繁体   English

将JNI基本类型放入同一数组

[英]Putting JNI primitive types into same array

I am trying to write static Java method that with given parameters, searches and invokes Method. 我正在尝试编写具有给定参数的静态Java方法,然后搜索并调用Method。

This method is supposed to have variable amount of arguments, and must be called from C++. 该方法应具有可变数量的参数,必须从C ++调用。 I tried few options, but i cannot get it done. 我尝试了几种选择,但我无法完成。 Is this even possible? 这有可能吗?

So far, i can store what types it contains and what position, and i can put jobject and jstring in same array. 到目前为止,我可以存储它包含的类型和位置,并且可以将jobject和jstring放在同一数组中。

If this is not possible, is it possible to refer either methodID found from JNI with Java's reflection or somehow pass reference to object in long. 如果无法做到这一点,则可以通过Java的反射引用从JNI找到的methodID,也可以长时间地以某种方式将引用传递给对象。 Such structure would be ok, since i can cast 64 bit Integer to everything else. 这样的结构还可以,因为我可以将64位Integer转换为其他所有内容。

If you need that array in JNI, use the jvalue union type as your array type. 如果在JNI中需要该数组,请使用jvalue联合类型作为您的数组类型。 Ex: jvalue myArray* = { (jint) 1, (jlong) 1000, (jboolean) false } 例如:jvalue myArray * = {(jint)1,(jlong​​)1000,(jboolean)false}

Java does not support jvalue nor does it support variadic functions, so if you need to pass that array of primitives to JNI from Java as a way of working around the limitation, you should use an Object array with primitive object wrappers like java.lang.Integer and call the value functions depending on type in JNI. Java不支持jvalue,也不支持可变参数函数,因此,如果您需要从Java将原语数组传递给JNI作为解决限制的一种方法,则应该使用带有原始对象包装器的Object数组,例如java.lang。根据JNI中的类型对整数和值函数进行调用。 Its possible, just a pain to implement. 可能的话,实施起来很痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM