Java Reflection Method Invoke invokeMethod(Object o, String fieldName)

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

Description

invoke Method

License

Apache License

Declaration

public static Object invokeMethod(Object o, String fieldName) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    public static Object invokeMethod(Object o, String fieldName) {
        try {//from w w w. java 2  s.  c o m
            final Method m = o.getClass().getMethod(fieldName);
            return m.invoke(o);
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            throw new RuntimeException("Reflection error!", e);
        }
    }
}

Related

  1. invokeMethod(Object cls, String methodName, Class paramClass, String paramValue)
  2. invokeMethod(Object destination, String methodName, Object argument)
  3. invokeMethod(Object handle, String methodName, Class[] parameterClasses, Object... args)
  4. invokeMethod(Object handler, String strMethod, Class[] cls, Object... params)
  5. invokeMethod(Object instance, String methodName, Class expectedReturnType)
  6. invokeMethod(Object o, String methodName, Object... args)
  7. invokeMethod(Object o, String methodName, Object[] params)
  8. invokeMethod(Object obj, Class type, String name, Class[] parameterTypes, Object[] parameters)
  9. invokeMethod(Object obj, Method method, Object... args)