Java Reflection Method Getter Invoke invokeGetterMethod(final Method method, final Object object)

Here you can find the source of invokeGetterMethod(final Method method, final Object object)

Description

Invokes the supplied method on the supplied object.

License

Open Source License

Parameter

Parameter Description
method to invoke
object that has the method

Exception

Parameter Description
IllegalArgumentExceptionif the method cannot be invoked

Return

value of the invoked method

Declaration

public static Object invokeGetterMethod(final Method method, final Object object) 

Method Source Code

//package com.java2s;
/* See LICENSE for licensing and NOTICE for copyright. */

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    /**//from   ww  w.j  a  v  a 2s  .co m
     * Invokes the supplied method on the supplied object.
     *
     * @param  method  to invoke
     * @param  object  that has the method
     *
     * @return  value of the invoked method
     *
     * @throws  IllegalArgumentException  if the method cannot be invoked
     */
    public static Object invokeGetterMethod(final Method method, final Object object) {
        try {
            return method.invoke(object);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new IllegalArgumentException(e);
        }
    }
}

Related

  1. invokeGetter(Object o, String name, boolean forceAccess)
  2. invokeGetter(Object obj, String methodName)
  3. invokeGetter(Object obj, String methodName, int defaultValue)
  4. invokeGetter(Object object, String field)
  5. invokeGetter(Object target, Method getter)
  6. invokeGetterSafe(Object o, String name, boolean forceAccess)
  7. invokeSetter(Object target, Class clazz, String methodName, String getterMethod, Object param)
  8. invokeStringGetterSafe(Object o, String name)