Notice: Undefined index: HTTP_ACCEPT_ENCODING in C:\server\web\www.showyounger.com\s-system.php on line 2
java反射动态调用方法 | 小样儿(ShowYounger)
小样儿,顶呱呱!!![http://www.showyounger.com]
- import java.lang.reflect.Method;
-
- public class Methoder {
-
-
-
-
- public static void main(String[] args) throws Exception {
-
-
- Class c = Class.forName("com.verran.ClassForName.Test");
-
- Class types[] =new Class[1];
- types[0]=Class.forName("java.lang.String");
- Method m = c.getMethod("sayHello",types);
- Test t = new Test();
- m.invoke(t,"sayHello" );
- }
-
- }
-
- package com.verran.ClassForName;
-
- public class Test {
-
- static {
- System.out.println("hi.....");
- }
- public String sayHello(String s){
- return s;
- }
- }