Here you can find the source of getSetterMethodByProperty(String propertyName, Class> beanClass, Class> setterParamType)
public static Method getSetterMethodByProperty(String propertyName, Class<?> beanClass, Class<?> setterParamType)
//package com.java2s; /*//from w w w . java 2 s . c o m Milyn - Copyright (C) 2006 - 2010 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (version 2.1) as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details: http://www.gnu.org/licenses/lgpl.txt */ import java.lang.reflect.Method; public class Main { public static Method getSetterMethodByProperty(String propertyName, Class<?> beanClass, Class<?> setterParamType) { return getSetterMethod(toSetterName(propertyName), beanClass, setterParamType); } public static Method getSetterMethod(String setterName, Object bean, Class<?> setterParamType) { return getSetterMethod(setterName, bean.getClass(), setterParamType); } public static Method getSetterMethod(String setterName, Class beanclass, Class<?> setterParamType) { Method[] methods = beanclass.getMethods(); for (Method method : methods) { if (method.getName().equals(setterName)) { Class<?>[] params = method.getParameterTypes(); if (params != null && params.length == 1 && params[0].isAssignableFrom(setterParamType)) { return method; } } } return null; } public static String toSetterName(String property) { StringBuffer setterName = new StringBuffer(); // Add the property string to the buffer... setterName.append(property); // Uppercase the first character... setterName.setCharAt(0, Character.toUpperCase(property.charAt(0))); // Prefix with "set"... setterName.insert(0, "set"); return setterName.toString(); } }