首页 > 其他 > 详细

如何通过反射调用对象的方法?

时间:2020-06-27 12:20:52      阅读:66      评论:0      收藏:0      [点我收藏+]

请看下面的代码:

import java.lang.reflect.Method;

class MethodInvokeTest {

public static void main(String[] args) throws Exception {

String str = "hello";

Method m = str.getClass().getMethod("toUpperCase");

System.out.println(m.invoke(str)); // HELLO

}

}

如何通过反射调用对象的方法?

原文:https://www.cnblogs.com/programb/p/13019683.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!