List of utility methods to do Reflection Method Invoke
Object | invokeMethod(Method method, Object object, Object... arguments) Fail-safe call. try { return method.invoke(object, arguments); } catch (IllegalAccessException e) { } catch (IllegalArgumentException e) { } catch (InvocationTargetException e) { return null; |
Object | invokeMethod(Method method, Object target) Invokes the given method on the passed target. return invokeMethod(method, target, new Object[0]); |
Object | invokeMethod(Method method, Object target) invoke Method return invokeMethod(method, target, new Object[0]); |
Object | invokeMethod(Method method, Object target) Invoke the specified Method against the supplied target object with no arguments. return invokeMethod(method, target, new Object[0]); |
T | invokeMethod(Method method, Object target, Class Invoke method and check the result. Object result = method.invoke(target); if (!expectedType.isInstance(result)) { throw new IllegalArgumentException( "Returned result must be instance of [" + expectedType.getName() + "]"); return expectedType.cast(result); |
Object | invokeMethod(Method method, Object target, Object... args) Invoke the specified Method against the supplied target object with the supplied arguments. try { return method.invoke(target, args); } catch (InvocationTargetException | IllegalAccessException e) { throw new IllegalStateException("Could not access method: " + e.getMessage()); |
Object | invokeMethod(Method method, Object target, Object... args) invoke Method Object obj = null; try { obj = method.invoke(target, args); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { ... |
Object | invokeMethod(Method method, Object target, Object... arguments) invoke Method if (!method.isAccessible()) { method.setAccessible(true); try { return method.invoke(target, arguments); } catch (IllegalAccessException ex) { throw new RuntimeException("", ex); |
Object | invokeMethod(Method method, Object target, Object... params) Invoke a method on the given target instance using the provided parameters. try { return method.invoke(target, params); } catch (Exception e) { throw new RuntimeException("Unable to invoke method " + method + " for " + target, e); |
Object | invokeMethod(Method method, Object target, Object[] args) Invoke the specified Method against the supplied target object with the supplied arguments. try { return method.invoke(target, args); } catch (IllegalAccessException ex) { handleReflectionException(ex); throw new IllegalStateException( "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage()); } catch (InvocationTargetException ex) { handleReflectionException(ex); ... |