Here you can find the source of invokeMethod(Object object, String propertyName)
public static Object invokeMethod(Object object, String propertyName)
//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; } } }