safeInvoke

open fun <T> safeInvoke(@NotNull method: Method, target: Any, args: Array<Any>): T

Safely invokes the specified method on the target object, unwrapping InvocationTargetException.

This method calls invoke but throws the target exception directly instead of wrapping it in InvocationTargetException, providing cleaner exception handling.

example

Method method = MyClass.class.getMethod("myMethod", String.class);
MyClass instance = new MyClass();
try {
    String result = FastInvoke.safeInvoke(method, instance, new Object[]{"hello"});
} catch (MyCustomException e) {
    // Handle the actual exception thrown by myMethod
}

Return

the result of the method invocation, or null if the method returns void

Parameters

method

the method to invoke; must not be null

target

the object on which to invoke the method, or null for static methods

args

the arguments to pass to the method; may be null if the method takes no arguments

<T>

the return type of the method

Throws

if the underlying method throws an exception or if invocation fails

if the method is not accessible

if the method is an instance method and target is null, or if the arguments are not appropriate for the method