Here you can find the source of invokeStaticMethod(String className, String method, Class[] paramTypes, Object[] paramValues)
Parameter | Description |
---|---|
className | a parameter |
method | a parameter |
paramTypes | a parameter |
paramValues | a parameter |
Parameter | Description |
---|---|
ClassNotFoundException | an exception |
NoSuchMethodException | an exception |
IllegalAccessException | an exception |
InvocationTargetException | an exception |
public static Object invokeStaticMethod(String className, String method, Class[] paramTypes, Object[] paramValues) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException
//package com.java2s; import java.lang.reflect.*; public class Main { /**//w w w .j a v a 2 s. c om * invoke a static method on a class. * * @param className * @param method * @param paramTypes * @param paramValues * @return * @throws ClassNotFoundException * @throws NoSuchMethodException * @throws IllegalAccessException * @throws InvocationTargetException */ public static Object invokeStaticMethod(String className, String method, Class[] paramTypes, Object[] paramValues) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { Class clz = Class.forName(className); Method m = clz.getDeclaredMethod(method, paramTypes); return m.invoke(null, paramValues); } }