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

2018-07-25  本文已影响166人  唐怀瑟_
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
    }
}
上一篇 下一篇

猜你喜欢

热点阅读