Let's say I have a java class
class NativeInterface{
public static native void access(Object obj);
}
And all I want to do is access the 2nd byte (for example) of that object.
I.e. I want to do something like this:
#include<jni.h>
#include "NativeInterface.h"
#include <stdio.h>
using byte = unsigned char;
/*
* Class: NativeInterface
* Method: access
* Signature: (Ljava/lang/Object)V
*/
JNIEXPORT void JNICALL Java_NativeInterface_access(JNIEnv* env, jclass _obsolete, jobject obj){
byte byte_array[] = obj;
printf("%c",byte_array[2]);
}
Now obviously, this doesn't work. obj
may not even be the java object.
(jobject
is defined in the jni.h and I haven't yet figured out what it does.)
So how do I do this?
(Trying this naive attempt will result in
error: initializer fails to determine size of ‘byte_array’
byte byte_array[] = obj;
^~~~
, btw.)