Java Reflection Method Getter Invoke invokeGetter(Object obj, String methodName)

Here you can find the source of invokeGetter(Object obj, String methodName)

Description

invoke Getter

License

Apache License

Declaration

public static Object invokeGetter(Object obj, String methodName) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

public class Main {
    public static Object invokeGetter(Object obj, String methodName) throws Exception {
        Method m = obj.getClass().getMethod(methodName, (Class[]) null);
        if (m != null) {
            if (m.getExceptionTypes().length != 0) {
                // It throws an exception. It's not a simple getter and setter
                return null;
            } else {
                return m.invoke(obj, (Object[]) null);
            }/*  w  ww. jav  a  2s  . c  o  m*/
        }
        return null;
    }
}

Related

  1. invokeGetter(Method getter, Object object)
  2. invokeGetter(Object bean, Method getter)
  3. invokeGetter(Object entity, String propertyName)
  4. invokeGetter(Object getterOwner, Method method)
  5. invokeGetter(Object o, String name, boolean forceAccess)
  6. invokeGetter(Object obj, String methodName, int defaultValue)
  7. invokeGetter(Object object, String field)
  8. invokeGetter(Object target, Method getter)
  9. invokeGetterMethod(final Method method, final Object object)