Here you can find the source of getGetter(Object instance, String methodName)
private static Method getGetter(Object instance, String methodName)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; public class Main { private static Map<String, Method> getters = new HashMap<String, Method>(); private static StringBuilder bld = new StringBuilder(); private static Method getGetter(Object instance, String methodName) { bld.setLength(0);/*w w w. ja v a2 s .co m*/ String key = bld.append(instance.getClass().getName()).append(".").append(methodName).toString(); Method getter = getters.get(key); if (getter == null) { Method[] ms = instance.getClass().getMethods(); for (Method m : ms) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0 && m.getReturnType() != null) { getter = m; getter.setAccessible(true); getters.put(key, getter); break; } } } return getter; } }