Java Method Call invokeNoArgsMethod(Object object, String methodName)

Here you can find the source of invokeNoArgsMethod(Object object, String methodName)

Description

Invoke no args method from the given instance.

License

LGPL

Parameter

Parameter Description
object the object
methodName the method name

Return

the result from invocation or null

Declaration

public static Object invokeNoArgsMethod(Object object, String methodName) 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    /**/* www.j av a  2s .co  m*/
     * Invoke no args method from the given instance.
     *
     * @param object
     *            the object
     * @param methodName
     *            the method name
     * @return the result from invocation or null
     */
    public static Object invokeNoArgsMethod(Object object, String methodName) {
        Method declaredMethod = null;
        try {
            declaredMethod = object.getClass().getDeclaredMethod(methodName, (Class<?>[]) null);
            declaredMethod.setAccessible(true);
            return declaredMethod.invoke(object, (Object[]) null);
        } catch (Exception e) {
            // probably not a weld proxy class
            throw new IllegalStateException("Failed to invoke method: " + methodName, e);
        }
    }
}

Related

  1. invokeHeritedMethod(Object target, String method, Class klass)
  2. invokeInstanceMethod(Object target, String methodName, Class type, Object arg)
  3. invokeIteratorCallable(String callableClassName, ClassLoader cl)
  4. invokeMXMethod(String methodName)
  5. invokeNoArgs(Object instance, Method method, Class returnType)
  6. invokeNonAccessibleMethod(Class clazz, String methodName, Object instance, Object... params)
  7. invokeNonArgMethod(Object object, String methodName)
  8. invokeObjectMethod(Object object, String name, Class paramTypes[], Object args[])
  9. invokeOrBailOut(Object invokee, Method method, Object[] params)