Here you can find the source of invokeStaticMethod(final Method method, final Object... args)
Parameter | Description |
---|---|
method | The method to invoke |
args | The invocation arguments (may be <code>null</code>) |
Parameter | Description |
---|---|
IllegalAccessException | when unable to access the specified method because access modifiers prevent it |
public static Object invokeStaticMethod(final Method method, final Object... args) throws InvocationTargetException, IllegalAccessException
//package com.java2s; /*/*from w w w. j a v a 2s . c om*/ * Copyright (C) 2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; public class Main { /** * Invoke the specified static {@link Method} with the supplied arguments. * * @param method The method to invoke * @param args The invocation arguments (may be <code>null</code>) * @return The invocation result, if any * @throws IllegalAccessException when unable to access the specified method because access modifiers prevent it * @throws java.lang.reflect.InvocationTargetException when a reflection invocation fails */ public static Object invokeStaticMethod(final Method method, final Object... args) throws InvocationTargetException, IllegalAccessException { if (method == null) { throw new IllegalArgumentException("Method must not be null."); } if (!Modifier.isStatic(method.getModifiers())) { throw new IllegalArgumentException("Method must be static."); } method.setAccessible(true); return method.invoke(null, args); } }