Here you can find the source of invokeVirtual(T o, Method method, Object... pa)
Parameter | Description |
---|---|
o | the instance on which the method will be invoked |
method | the method |
pa | the arguments |
T | generic type of the instance |
R | generic type of the result |
public static <T, R> R invokeVirtual(T o, Method method, Object... pa)
//package com.java2s; //License from project: Apache License import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { /**/*w ww . j a v a2s. c o m*/ * * Invoke a virtual {@link Method method}. This method will convert all checked exception * to corresponding runtime exception * @param o the instance on which the method will be invoked * @param method the method * @param pa the arguments * @param <T> generic type of the instance * @param <R> generic type of the result * @return result of method invocation */ public static <T, R> R invokeVirtual(T o, Method method, Object... pa) { try { return (R) method.invoke(o, pa); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException(); } } }