Here you can find the source of invoke(Object object, String methodName)
public static Object invoke(Object object, String methodName) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Google, Inc.//from w w w. jav a 2 s.c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Google, Inc. - initial API and implementation *******************************************************************************/ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static Object invoke(Object object, String methodName) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Class<?> objectClass = object.getClass(); Method method; try { method = objectClass.getMethod(methodName, new Class<?>[] {}); } catch (NoSuchMethodException e) { method = objectClass.getDeclaredMethod(methodName, new Class<?>[] {}); method.setAccessible(true); } return method.invoke(object, new Object[] {}); } }