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

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
    }
}
posted @ 2018-04-21 14:50  爱吃醋的工程师  阅读(703)  评论(0)    收藏  举报