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

voidinvokeSetFieldValue(Object bean, Field field, Object value)
invoke Set Field Value
try {
    field.setAccessible(true);
    field.set(bean, value);
} catch (Exception e) {
    throw new RuntimeException(e);
ObjectinvokeSilent(Object obj, String methodName, Class[] parameterTypes, Object[] args)
invoke Silent
try {
    return invoke(obj, methodName, parameterTypes, args);
} catch (Exception e) {
    return null;
ObjectinvokeSimple(Object target, String name)
invoke Simple
Method m = target.getClass().getMethod(name);
if (m == null) {
    throw new IllegalArgumentException("method:(" + name + ") not found");
return m.invoke(target);
ObjectinvokeTarget(Method method, Object obj, Object... args)
invoke Target
try {
    return method.invoke(obj, args);
} catch (InvocationTargetException e) {
    throw e.getCause();
voidinvokeTargetCheckPoint(String resuming_checkpoint_path, Object jobObject, final java.util.Map globalMap)
invoke Target Check Point
String currentJob_checkpoint_path = null;
if (resuming_checkpoint_path != null) {
    int indexOf = resuming_checkpoint_path.indexOf("/NODE:");
    if (indexOf != -1) {
        currentJob_checkpoint_path = resuming_checkpoint_path.substring(0, indexOf);
    } else {
        currentJob_checkpoint_path = resuming_checkpoint_path;
String currentJob_subJob_resuming = null;
if (currentJob_checkpoint_path != null) {
    int indexOf = currentJob_checkpoint_path.indexOf("/SUBJOB:");
    if (indexOf != -1) {
        currentJob_subJob_resuming = currentJob_checkpoint_path.substring(indexOf + 8);
String subjobMethodName = currentJob_subJob_resuming + "Process";
if (currentJob_subJob_resuming != null) {
    for (java.lang.reflect.Method m : jobObject.getClass().getMethods()) {
        if (m.getName().compareTo(subjobMethodName) == 0) {
            m.invoke(jobObject, new Object[] { globalMap });
            break;
voidinvokeTargetMethods(Object obj, T data, List methods)
invoke Target Methods
for (Method target : methods) {
    for (Parameter paramType : target.getParameters()) {
        Class<?> parClass = paramType.getType();
        if (parClass.isAssignableFrom(data.getClass())) {
            target.invoke(obj, data);
StringinvokeToStringMethod(Object value, Class type)
invoke To String Method
try {
    Method method = customClass.getMethod("convertToString", new Class[] { type });
    String result = (String) method.invoke(null, new Object[] { value });
    return result;
} catch (NoSuchMethodException e) {
    throw new RuntimeException("can not find the method convertToString(" + type.getName()
            + ") in converter util class " + customClass.getName(), e);
} catch (IllegalAccessException e) {
...
TinvokeUnchecked(Method method, Object target, Object... arguments)
Invokes the specified method without throwing any checked exceptions.
try {
    @SuppressWarnings("unchecked")
    T result = (T) method.invoke(target, arguments);
    return result;
} catch (IllegalAccessException ex) {
    throw new IllegalArgumentException("Method " + method.getName() + " is not publicly accessible.", ex);
} catch (InvocationTargetException ex) {
    if (ex.getCause() instanceof Error) {
...
ObjectinvokeUnwrapException(final Object target, final Method method, @Nullable final Object[] args)
invoke Unwrap Exception
try {
    return method.invoke(target, args);
} catch (final InvocationTargetException e) {
    throw e.getCause();
ObjectinvokeValue(AnnotatedElement element, Class annotationClass)
Reads the value from the annotation using reflection.
try {
    final Annotation annotation = element.getAnnotation(annotationClass);
    if (annotation != null) {
        final Method valueMethod = annotationClass.getDeclaredMethod("value");
        return valueMethod.invoke(annotation);
} catch (final SecurityException e) {
    e.printStackTrace();
...