Get<type>Field Routines - GetDoubleField
NativeType Get<type>Field
(JNIEnv *env, jobject obj,
jfieldID fieldID);
This family of accessor routines returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling
GetFieldID()
. (GetDoubleField)
The following table describes the Get<type>Field routine name and result type. You should replace type in Get<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-1a Get<type>Field Family of Accessor Routines
LINKAGE:
Indices in the JNIEnv interface function table:
Table 4-1b Get<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.RETURNS:
Returns the content of the field.
Example - GetDoubleField
JNIEXPORT void JNICALL Java_Employee_raiseSalary(JNIEnv* env, jobject this_obj, jdouble byPercent)
{
/* get the class */
jclass class_Employee = (*env)->GetObjectClass(env, this_obj);
/* get the field ID */
jfieldID id_salary = (*env)->GetFieldID(env, class_Employee, "salary", "D");
/* get the field value */
jdouble salary = (*env)->GetDoubleField(env, this_obj, id_salary);
salary *= 1 + byPercent / 100;
/* set the field value */
(*env)->SetDoubleField(env, this_obj, id_salary, salary);
}
JNIEXPORT void JNICALL Java_Employee_raiseSalary(JNIEnv* env, jobject this_obj, jdouble byPercent)
{
/* get the class */
jclass class_Employee = (*env)->GetObjectClass(env, this_obj);
/* get the field ID */
jfieldID id_salary = (*env)->GetFieldID(env, class_Employee, "salary", "D");
/* get the field value */
jdouble salary = (*env)->GetDoubleField(env, this_obj, id_salary);
salary *= 1 + byPercent / 100;
/* set the field value */
(*env)->SetDoubleField(env, this_obj, id_salary, salary);
}