⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jnistaticwrapperimpl.cpp

📁 java 编程源代码
💻 CPP
字号:
// JNIStaticWrapperImpl.cpp
// Integrates with JNI to retrieve the static
// members of the given MathConstant object

// C++ core headers
#include <iostream.h>

// header produced by javah
#include "JNIStaticWrapper.h"

JNIEXPORT void JNICALL Java_JNIStaticWrapper_printStaticMembers
   (JNIEnv * env, jobject thisObject, jobject MathObject) 
{
   jclass constantClass;
   jfieldID fieldID;
   jmethodID methodID; 
  
   // get class of MathObject
   constantClass = env->GetObjectClass( MathObject );

   // retrieve FieldID of static member variable E
   fieldID = env->GetFieldID( constantClass, "E", "D" );
   
   // retrieves double at given fieldID
   const jdouble E = env->GetDoubleField( MathObject, fieldID );
   
   // output to show proper retrieval
   cout << "Value of E in MathConstants is " << E << endl;

   fieldID = env->GetStaticFieldID( constantClass, "PI", "D" );
   const jdouble PI = env->GetStaticDoubleField( constantClass, fieldID );
   
   cout << "Value of PI in MathConstants is " << PI << endl;
   
   // retrieve static method id
   methodID = env->GetStaticMethodID( 
      constantClass, "getPI", "()D" );

   // invoke static method getPI
   env->CallStaticDoubleMethod( constantClass , methodID);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -