Java Reflection Method Invoke invokeMethod(Object object, String propertyName)

Here you can find the source of invokeMethod(Object object, String propertyName)

Description

invoke Method

License

Apache License

Declaration

public static Object invokeMethod(Object object, String propertyName) 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {

    public static Object invokeMethod(Object object, String propertyName) {
        try {/*  w  w  w. java2s  .c o  m*/
            Method getterMethod = object.getClass().getMethod(propertyName);
            return getterMethod.invoke(object);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Object invokeMethod(Object object, String propertyName, Object... args) {
        try {
            Method getterMethod = object.getClass().getMethod(propertyName);
            return getterMethod.invoke(object, args);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. invokeMethod(Object object, String methodName, Object arg, Class argType)
  2. invokeMethod(Object object, String methodName, Object... parameters)
  3. invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)
  4. invokeMethod(Object object, String methodName, Object[] params, Object[] result)
  5. invokeMethod(Object object, String name, Object... arguments)
  6. invokeMethod(Object objectInstance, String methodToInvoke, Class[] parameterTypes, Object[] instanceParameters)
  7. invokeMethod(Object owner, String methodName)
  8. invokeMethod(Object owner, String methodName, Object[] args)
  9. invokeMethod(Object parent, String method, Class[] paramTypes, Object[] args)