ITPub博客

首页 > IT职业 > IT图书 > 反射

反射

IT图书 作者:hoonty 时间:2021-09-09 09:59:46 0 删除 编辑

## 反射的复习 ##

//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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4222/viewspace-2814790/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: jvm 信息 jmap使用
请登录后发表评论 登录
全部评论

注册时间:2019-08-12

  • 博文量
    94
  • 访问量
    1273