Here you can find the source of invoke(Class
Parameter | Description |
---|---|
returnType | a parameter |
m | a parameter |
obj | a parameter |
args | a parameter |
T | a parameter |
Parameter | Description |
---|---|
InvocationTargetException | an exception |
@SuppressWarnings("unchecked") public static <T> T invoke(Class<T> returnType, Method m, Object obj, Object... args) throws InvocationTargetException
//package com.java2s; // SMSLib is distributed under the terms of the Apache License version 2.0 import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { /**//from w w w . java 2 s .co m * Invokes the given method on the given object with the given arguments. * The result is cast to T and every kind of exception is wrapped as * RuntimeException * @param returnType * @param m * @param obj * @param args * @param <T> * @return The result of the method invocation * @throws InvocationTargetException */ @SuppressWarnings("unchecked") public static <T> T invoke(Class<T> returnType, Method m, Object obj, Object... args) throws InvocationTargetException { try { return (T) m.invoke(obj, args); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } /** * Invokes the given void method on the given object with the given arguments. * @param m * @param obj * @param args * @throws InvocationTargetException * @throws IllegalArgumentException */ public static void invoke(Method m, Object obj, Object... args) throws InvocationTargetException { try { m.invoke(obj, args); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } }