Here you can find the source of invokeNoArgsMethod(Object object, String methodName)
Parameter | Description |
---|---|
object | the object |
methodName | the method name |
public static Object invokeNoArgsMethod(Object object, String methodName)
//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); } } }