手记

反射

## 反射的复习 ##

//1.装载字节码

Class<?> clazz = Demo.class.getClassLoader().loadClass("Dialog");

//2.查找方法

Method method = clazz.getDeclaredMethod("showDialog", String.class);

//3.调用方法

method.invoke(clazz.newInstance(), "利用反射调用Dialog中的showDialog方法");

## C调用java中方法的步骤 ##

//1.find class

//jclass      (*FindClass)(JNIEnv*, const char*);

jclass clazz = (*env)->FindClass(env,"com/itheima/alipay01/MainActivity");

//2.get method id

//jmethodID   (*GetMethodID)(JNIEnv*, jclass, const char*, const char*);

jmethodID methodid = (*env)->GetMethodID(env, clazz, "showDialog", "(Ljava/lang/String;)V");

//3.call void  methoid

//void        (*CallVoidMethod)(JNIEnv*, jobject, jmethodID, ...);

(*env)->CallVoidMethod(env, obj, methodid, "yong hu mi ma");

原文链接:http://www.apkbus.com/blog-807598-61370.html

0人推荐
随时随地看视频
慕课网APP