Mega Code Archive

 
Categories / Java / Reflection
 

Call a static method of a class with reflection

import java.lang.reflect.Method; /**  * Handy reflection routines.  */ public abstract class Reflect {   /**    * Call a static method of a class.    */   public static Object callStaticMethod (String className,                                           String methodName,                                          Class[] signature,                                          Object[] args)        throws Exception {              Class cls = Class.forName (className);       Method method = cls.getMethod (methodName, signature);       return method.invoke (cls, args);   } }