本帖最后由 在学野马 于 2014-10-1 22:16 编辑
- public class test1{
- public static void main(String[] args) throws Exception
- {
- Class clazz = Class.forName("com.itheima.RyReflect");
- Method method = clazz.getMethod("printString", String.class);
- method.invoke(clazz.newInstance(), "reflect is String");
- }
- }
- class RyReflect
- {
- public void printString(String str)
- {
- System.out.println(str);
- }
- }
复制代码
|