Here you can find the source of invoke(Object source, String key)
@SuppressWarnings("rawtypes") public static Object invoke(Object source, String key)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; import java.util.Map; public class Main { @SuppressWarnings("rawtypes") public static Object invoke(Object source, String key) { if (source instanceof Map) { return valueOfMap((Map) source, key); } else {//from www.j ava2 s . c o m return valueOfObj(source, key); } } @SuppressWarnings("rawtypes") private static Object valueOfMap(Map map, String key) { if (map.isEmpty() || key == null || key.trim() == "") { return null; } return map.get(key); } private static Object valueOfObj(Object o, String property) { if (o == null) { return null; } if (property == null || "".equals(property.trim())) { return o; } String methodName = "get" + property.substring(0, 1).toUpperCase() + property.substring(1); Object result = null; try { Method method = o.getClass().getMethod(methodName); result = method.invoke(o, new Object[] {}); } catch (Exception e) { result = null; e.printStackTrace(); } return result; } }