## 反射的复习 ##
//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");
共同学习,写下你的评论
评论加载中...
作者其他优质文章