Java Method Call invokeGet(Object o, String fieldName)

Here you can find the source of invokeGet(Object o, String fieldName)

Description

invoke Get

License

Open Source License

Declaration


public static Object invokeGet(Object o, String fieldName) 

Method Source Code

//package com.java2s;

import java.lang.reflect.Method;

public class Main {

    public static Object invokeGet(Object o, String fieldName) {
        Method method = getGetMethod(o.getClass(), fieldName);
        try {/*from   w w w  . j a va  2  s . com*/
            return method.invoke(o, new Object[0]);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Method getGetMethod(Class objectClass, String fieldName) {
        StringBuffer sb = new StringBuffer();
        sb.append("get");
        sb.append(fieldName.substring(0, 1).toUpperCase());
        sb.append(fieldName.substring(1));
        try {
            return objectClass.getMethod(sb.toString());
        } catch (Exception e) {
        }
        return null;

    }
}

Related

  1. invokeExactField(Object object, String fieldName)
  2. invokeExactMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)
  3. invokeFunction(Object iFunction, String funcName, String param)
  4. invokeFunctions(Object iFunction, String funcName)
  5. invokeGenericMethodOneArg(final Object obj, final String methodName, final Object arg)
  6. invokeGetClasspathMethodIfItExists(ClassLoader cl)
  7. invokeGetMethodWithSameName(Object object, Method method)
  8. invokeHeritedMethod(Object target, String method, Class klass)
  9. invokeInstanceMethod(Object target, String methodName, Class type, Object arg)