Here you can find the source of getSetter(Object instance, String methodName)
private static Method getSetter(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> setters = new HashMap<String, Method>(); private static StringBuilder bld = new StringBuilder(); private static Method getSetter(Object instance, String methodName) { bld.setLength(0);/*from w w w . j av a 2 s. com*/ String key = bld.append(instance.getClass().getName()).append(".").append(methodName).toString(); Method setter = setters.get(key); if (setter == null) { Method[] ms = instance.getClass().getMethods(); for (Method m : ms) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 1) { setter = m; setter.setAccessible(true); setters.put(key, setter); break; } } } return setter; } }