Here you can find the source of invokeStaticMethod(String className, String methodName)
Parameter | Description |
---|---|
className | Class name, e.g. java.lang.Object |
methodName | Name of static method to invoke |
Parameter | Description |
---|---|
Throwable | If there is some unexpected problem during execution |
public static Object invokeStaticMethod(String className, String methodName) throws Throwable
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { /**//from ww w .jav a 2 s . c om * Invokes static method {@code methodName} in class by given {@code className} without parameters. * @param className Class name, e.g. {@code java.lang.Object} * @param methodName Name of static method to invoke * @return Result of invoked method * @throws Throwable If there is some unexpected problem during execution */ public static Object invokeStaticMethod(String className, String methodName) throws Throwable { return invokeStaticMethod(className, methodName, new Class<?>[] {}, new Object[] {}); } /** * Invokes static method {@code methodName} in class by given {@code className}, {@code paramTypes} and {@code paramValues}. * @param className Class name, e.g. {@code java.lang.Object} * @param methodName Name of static method to invoke * @param paramTypes Array containing parameter types * @param paramValues Array containing parameter values * @return Result of invoked method * @throws Throwable If there is some unexpected problem during execution */ public static Object invokeStaticMethod(String className, String methodName, Class<?>[] paramTypes, Object[] paramValues) throws Throwable { Class<?> clazz = Class.forName(className); Method method = clazz.getMethod(methodName, paramTypes); return method.invoke(null, paramValues); } }