开发者

Checking if a Java object is of an array type in JNI

开发者 https://www.devze.com 2022-12-24 07:06 出处:网络
Say I have a MyClass class in Java, is there a way to check in JNI that a jobject is a MyClass[][]? My initial idea was to use env->IsInstanceOf(myobj, myArrayClass), but calling env->FindClass

Say I have a MyClass class in Java, is there a way to check in JNI that a jobject is a MyClass[][]?

My initial idea was to use env->IsInstanceOf(myobj, myArrayClass), but calling env->FindClass("[MyClass") throws a 开发者_如何学编程NoClassDefFoundError.


I know this question is old but...

To find a class of your array, use:

env->FindClass("[[Lmy/package/MyClass;")


A little rusty on JNI, but a couple of things:

Call FindClass() on your fully qualified classname, using a "/" as a separator instead of dots. So, for instance if your class is "my.package.MyClass", you would call env->FindClass("my/package/MyClass")

Since you have a two-dimensional array of your object type, you need to call env->GetObjectArrayElement() twice; once to get a row and another time to get a distinct element. Then you can call env->IsInstanceOf() on that element. Make sure you look up the correct signatures for these JNI calls, I've left them as an exercise for the reader :)

0

精彩评论

暂无评论...
验证码 换一张
取 消