以下是一个测试类
java 代码
- package com.tyq.reflection;
- import java.lang.reflect.Method;
- public class Test {
- public void func(String hello)
- {
- System.out.println(hello);
- }
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- Class<Test> test = Test.class;
- Object obj = test.newInstance();
- //Method method = test.getMethods()[0];
- //method.invoke(obj, "hello");
- Method m = test.getMethod("func" ,new Class[]{String.class} );
- m.invoke(obj, "hello");
- }
- }