1 30 31 package rcm.util; 32 33 import java.lang.reflect.*; 34 35 38 public abstract class Reflect { 39 43 public static Object newInstance (String className, 44 Class [] signature, 45 Object [] args) 46 throws Exception { 47 48 Class cls = Class.forName (className); 49 Constructor constructor = cls.getConstructor (signature); 50 return constructor.newInstance (args); 51 } 52 53 56 public static Object callMethod (Object obj, 57 String methodName, 58 Class [] signature, 59 Object [] args) 60 throws Exception { 61 62 Class cls = obj.getClass (); 63 Method method = cls.getMethod (methodName, signature); 64 return method.invoke (obj, args); 65 } 66 67 70 public static Object callStaticMethod (String className, 71 String methodName, 72 Class [] signature, 73 Object [] args) 74 throws Exception { 75 76 Class cls = Class.forName (className); 77 Method method = cls.getMethod (methodName, signature); 78 return method.invoke (cls, args); 79 } 80 } 81 82 | Popular Tags |