Java Utililty Methods Method Call

List of utility methods to do Method Call

Description

The list of methods to do Method Call are organized into topic(s).

Method

voidinvokePrimivite(Object entity, Method writeMethod, Class propertyType, String propertyValue)
invoke Primivite
if (isByte(propertyType)) {
    writeMethod.invoke(entity, Byte.parseByte(propertyValue));
} else if (isShort(propertyType)) {
    writeMethod.invoke(entity, Short.parseShort(propertyValue));
} else if (isInt(propertyType)) {
    writeMethod.invoke(entity, Integer.parseInt(propertyValue));
} else if (isLong(propertyType)) {
    writeMethod.invoke(entity, Long.parseLong(propertyValue));
...
ObjectinvokePrivate(Class clazz, Object instance, String methodName, Class[] argTypes, Object[] args)
invoke Private
try {
    Method method = clazz.getDeclaredMethod(methodName, argTypes);
    method.setAccessible(true);
    return method.invoke(instance, args);
} catch (Exception e) {
    throw new RuntimeException(e);
ObjectinvokePrivate(String name, final Object obj, Object[] objects)
invoke Private
Method method = null;
Class<?> objClass = obj instanceof Class ? (Class<?>) obj : obj.getClass();
while (objClass != null && method == null) {
    for (Method m : objClass.getDeclaredMethods()) {
        if (name.equals(m.getName()) && (objects == null && m.getParameterTypes().length == 0)
                || (objects != null && objects.length == m.getParameterTypes().length)) {
            method = m;
            break;
...
ObjectinvokePrivateMethod(Method method, Object object, Object... args)
invoke Private Method
try {
    method.setAccessible(true);
    return method.invoke(object, args);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
    return null;
} finally {
    method.setAccessible(false);
TinvokePrivateMethod(Object instance, String name, Object... args)
invoke Private Method
Class<?>[] clazArray = new Class<?>[args.length];
for (int i = 0; i < args.length; i++) {
    clazArray[i] = args[i].getClass();
try {
    Method method = instance.getClass().getDeclaredMethod(name, clazArray);
    method.setAccessible(true);
    T result = (T) method.invoke(instance, args);
...
ObjectinvokePrivateMethod(Object obj, String methodName, Class[] parameterTypes, Object[] args)
Invoke a private Java method by reflection
Method m = obj.getClass().getDeclaredMethod(methodName, parameterTypes);
m.setAccessible(true);
return m.invoke(obj, args);
voidinvokePrivateMethod(String methodName, Class clazz, Object object)
invoke Private Method
try {
    final Method method = clazz.getDeclaredMethod(methodName);
    method.setAccessible(true);
    method.invoke(object);
} catch (Exception e) {
    e.printStackTrace();
    return;
ObjectinvokeProperty(Object obj, String property)
Invoke the method/field getter on the Object.
if ((property == null) || (property.length() == 0)) {
    return null; 
Class cls = obj.getClass();
Object[] oParams = {};
Class[] cParams = {};
try {
    Method method = cls.getMethod(createMethodName(GET, property), cParams);
...
ObjectinvokeProtectedMethod(Class c, String method, Object... args)
invoke Protected Method
return invokeProtectedMethod(c, null, method, args);
TinvokeProtectedMethod(Object o, Object[] args, String methodName, Class[] types)
Invokes a protected method on the specified object.
try {
    Method m = getDeclaredMethod(o.getClass(), methodName, types);
    m.setAccessible(true);
    return (T) m.invoke(o, args);
} catch (SecurityException e) {
    throw new RuntimeException(e);
} catch (NoSuchMethodException e) {
    throw new RuntimeException(e);
...