[英]JNI c to Java with a class
I have an .obj parser, code is: 我有一个.obj解析器,代码为:
class Model {
public:
List *coords;
List *tcoords;
List *normals;
List *faces;
Model() {
coords=new List();
tcoords=new List();
normals=new List();
faces=new List();
}
~Model() {
delete(coords);
delete(tcoords);
delete(normals);
delete(faces);
}
};
this is a model file parser tool, which is parse a big file. 这是一个模型文件解析器工具,它解析一个大文件。 The List is a linkedlist. 该列表是一个链表。 (String array, char*) (字符串数组,char *)
How can I return this class to Java from C++? 如何从C ++将此类返回Java? I know how can return a simple String Array with NewObjectArray, but what is the way to return a Class? 我知道如何用NewObjectArray返回一个简单的String Array,但是返回Class的方法是什么?
Thanks, Leslie 谢谢莱斯利
Typically, you create a peer class on the Java side that holds a pointer to the class in a long variable. 通常,您在Java端创建一个对等类,该对等类在long变量中保存指向该类的指针。
Jim S. 吉姆·S。
In C++ code you can instantiate any Java object by calling env->NewObject() method and passing appropriate constructor signature to it. 在C ++代码中,您可以通过调用env-> NewObject()方法并将适当的构造函数签名传递给它来实例化任何Java对象。 Constructors have special name <init>
. 构造函数具有特殊名称<init>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.