/** * Returns true if the method exists on the supplied {@code target}. */ public boolean isSupported(T target) { return getMethod(target.getClass()) != null; }
/** * Returns true if the method exists on the supplied {@code target}. */ public boolean isSupported(T target) { return getMethod(target.getClass()) != null; }
/** * Invokes the method on {@code target} with {@code args}. If the method does not exist or is not * public then {@code null} is returned. See also {@link #invokeOptionalWithoutCheckedException}. * * @throws IllegalArgumentException if the arguments are invalid * @throws InvocationTargetException if the invocation throws an exception */ public Object invokeOptional(T target, Object... args) throws InvocationTargetException { Method m = getMethod(target.getClass()); if (m == null) { return null; } try { return m.invoke(target, args); } catch (IllegalAccessException e) { return null; } }
/** * Invokes the method on {@code target} with {@code args}. If the method does not exist or is not * public then {@code null} is returned. See also {@link #invokeOptionalWithoutCheckedException}. * * @throws IllegalArgumentException if the arguments are invalid * @throws InvocationTargetException if the invocation throws an exception */ public Object invokeOptional(T target, Object... args) throws InvocationTargetException { Method m = getMethod(target.getClass()); if (m == null) { return null; } try { return m.invoke(target, args); } catch (IllegalAccessException e) { return null; } }
/** * Invokes the method on {@code target} with {@code args}. Throws an error if the method is not * supported. See also {@link #invokeWithoutCheckedException(Object, Object...)}. * * @throws IllegalArgumentException if the arguments are invalid * @throws InvocationTargetException if the invocation throws an exception */ public Object invoke(T target, Object... args) throws InvocationTargetException { Method m = getMethod(target.getClass()); if (m == null) { throw new AssertionError("Method " + methodName + " not supported for object " + target); } try { return m.invoke(target, args); } catch (IllegalAccessException e) { // Method should be public: we checked. AssertionError error = new AssertionError("Unexpectedly could not call: " + m); error.initCause(e); throw error; } }
/** * Invokes the method on {@code target} with {@code args}. Throws an error if the method is not * supported. See also {@link #invokeWithoutCheckedException(Object, Object...)}. * * @throws IllegalArgumentException if the arguments are invalid * @throws InvocationTargetException if the invocation throws an exception */ public Object invoke(T target, Object... args) throws InvocationTargetException { Method m = getMethod(target.getClass()); if (m == null) { throw new AssertionError("Method " + methodName + " not supported for object " + target); } try { return m.invoke(target, args); } catch (IllegalAccessException e) { // Method should be public: we checked. AssertionError error = new AssertionError("Unexpectedly could not call: " + m); error.initCause(e); throw error; } }