Code Review

Reflection API

?

public class ReflectionUtils {
    /**
     * The method takes "Class", the name of the field and returns "Field".
     *
     * @param className incoming parameter
     * @param fieldName incoming parameter
     * @return "Field"
     */
    public Field getFieldFromName(Class className, String fieldName) {
        try {
            Field field = className.getDeclaredField(fieldName);
            return field;
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
    }

?

public void callObjectMethod(Object object, Method method)
        throws InvocationTargetException, IllegalAccessException {
    method.setAccessible(true);
    method.invoke(object);
}

public void callObjectMethodWithArguments(Method method, Object object, Object... arguments)
        throws InvocationTargetException, IllegalAccessException {
    method.setAccessible(true);
    method.invoke(object, arguments);
}

?

public Field printField(Class<?> cls, String fieldName) {
    Field field = null;
    try {
        field = cls.getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
        LOGGER.warning(e.getMessage());
    }
    return field;
}
public Method[] printArrayMethods(Class<?> cls) {
    Method[] methods = cls.getDeclaredMethods();
    for (Method method : methods) {
        LOGGER.info("Method name: " + method.getName() + " Return type: " + method.getReturnType().getName());

        Class<?>[] params = method.getParameterTypes();
        for (Class<?> paramType : params) {
            LOGGER.info("Parameter: " + paramType.getName());
        }
    }
    return methods;
}