Java Utililty Methods Reflection Method Getter Invoke

List of utility methods to do Reflection Method Getter Invoke

Description

The list of methods to do Reflection Method Getter Invoke are organized into topic(s).

Method

ObjectinvokeGetMethod(Object obj, String getterName)
invoke Get Method
return obj.getClass().getDeclaredMethod(getterName).invoke(obj);
ObjectinvokeGetter(Method getter, Object object)
invoke Getter
try {
    getter.setAccessible(true);
    return getter.invoke(object, new Object[0]);
} catch (IllegalAccessException e) {
    throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
    throw new IllegalStateException(e);
TinvokeGetter(Object bean, Method getter)
Invokes a getter method on a given bean
boolean accessible = getter.isAccessible();
getter.setAccessible(true);
T result = null;
try {
    result = (T) getter.invoke(bean);
} finally {
    getter.setAccessible(accessible);
return result;
ObjectinvokeGetter(Object entity, String propertyName)
Returns the value of a property on an entity based on its name.
Object result = null;
if (propertyName != null && entity != null) {
    propertyName = propertyName.replaceAll("/", ".");
    Object o = entity;
    String pty = propertyName;
    int index = propertyName.indexOf(".");
    if (index != -1) {
        o = invokeGetter(entity, propertyName.substring(0, index));
...
ObjectinvokeGetter(Object getterOwner, Method method)
invoke Getter
try {
    return method.invoke(getterOwner);
} catch (Exception e) {
    return null;
ObjectinvokeGetter(Object o, String name, boolean forceAccess)
invoke Getter
Method getterMtd = o.getClass().getMethod(name, null);
if (forceAccess) {
    getterMtd.setAccessible(true);
return getterMtd.invoke(o, null);
ObjectinvokeGetter(Object obj, String methodName)
invoke Getter
Method m = obj.getClass().getMethod(methodName, (Class[]) null);
if (m != null) {
    if (m.getExceptionTypes().length != 0) {
        return null;
    } else {
        return m.invoke(obj, (Object[]) null);
return null;
intinvokeGetter(Object obj, String methodName, int defaultValue)
Invokes the specified getter method if it exists.
try {
    Method method = obj.getClass().getMethod(methodName, new Class[0]);
    Object result = method.invoke(obj, new Object[0]);
    return ((Integer) result).intValue();
} catch (NoSuchMethodException e) {
    return defaultValue;
} catch (IllegalAccessException e) {
    return defaultValue;
...
ObjectinvokeGetter(Object object, String field)
invoke Getter
Method method = getGetterMethod(object.getClass(), field);
return method.invoke(object);
ObjectinvokeGetter(Object target, Method getter)
call getter and return object.
RuntimeException re = new RuntimeException("Error trying to get value: " + getter.toString());
Object result = null;
try {
    result = getter.invoke(target, new Object[] {});
} catch (IllegalArgumentException e) {
    re.initCause(e);
    throw re;
} catch (IllegalAccessException e) {
...