I've seen examples of using a long/jlong to allow a Java object to hold onto a C++ pointer:
class Foo {
private native long create();
}
struct Foo { };
JNIEXPORT jlong JNICALL Java_Foo_create
(JNIEnv *, jobject)
{
return (jlong) (new Foo);
}
This makes me feel just a little bit nervous because it assumes that a pointer will fit in 64 bits; that is untrue for example on OS/400.
Is there a safer solution, for example a Java standard library class that encapsulates a C++ pointer?