Set<type>Field Routines - SetLongField
void
Set<type>Field(JNIEnv *env, jobject obj, jfieldID fieldID,
NativeType value);
This family of accessor routines sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling
GetFieldID()
. (SetLongField)
The following table describes the Set<type>Field routine name and value type. You should replace type in Set<type>Field with the Java type of the field, or use one of the actual routine names from the table, and replace NativeType with the corresponding native type for that routine.
Table 4-2a Set<type>Field Family of Accessor Routines
LINKAGE:
Indices in the JNIEnv interface function table.
Table 4-2b Set<type>Field Family of Accessor Routines
PARAMETERS:
env
: the JNI interface pointer.obj
: a Java object (must not be NULL
).fieldID
: a valid field ID.value
: the new value of the field.
Example - SetLongField
public abstract class CPointer { protected long peer; public native void copyIn(int bOff, int[] buf, int off,int len); public native void copyOut(...); ... }
FID_CPointer_peer
is the precomputed field ID forCPointer.peer
JNIEXPORT void JNICALL
Java_CMalloc_free(JNIEnv *env, jobject self) { long peer = env->GetLongField(self, FID_CPointer_peer); if (peer == 0) { return; /* not an error, freed previously */ } free((void *)peer); peer = 0; env->SetLongField(self, FID_CPointer_peer, peer); }