Here you can find the source of getGetterMethodByProperty(String propertyName, Class> beanClass, Class> returnType)
public static Method getGetterMethodByProperty(String propertyName, Class<?> beanClass, Class<?> returnType)
//package com.java2s; /*/* ww w. ja v a 2s . 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 getGetterMethodByProperty(String propertyName, Class<?> beanClass, Class<?> returnType) { Method getter = getGetterMethod(toGetterName(propertyName), beanClass, returnType); if (getter == null) { getter = getGetterMethod(toIsGetterName(propertyName), beanClass, returnType); } return getter; } public static Method getGetterMethod(String getterName, Object bean, Class<?> returnType) { return getGetterMethod(getterName, bean.getClass(), returnType); } public static Method getGetterMethod(String getterName, Class beanclass, Class<?> returnType) { Method[] methods = beanclass.getMethods(); for (Method method : methods) { if (method.getName().equals(getterName)) { if (returnType != null) { if (method.getReturnType().isAssignableFrom(returnType)) { return method; } } else { return method; } } } return null; } public static String toGetterName(String property) { StringBuffer getterName = new StringBuffer(); // Add the property string to the buffer... getterName.append(property); // Uppercase the first character... getterName.setCharAt(0, Character.toUpperCase(property.charAt(0))); // Prefix with "get"... getterName.insert(0, "get"); return getterName.toString(); } public static String toIsGetterName(String property) { StringBuffer getterName = new StringBuffer(); // Add the property string to the buffer... getterName.append(property); // Uppercase the first character... getterName.setCharAt(0, Character.toUpperCase(property.charAt(0))); // Prefix with "is"... getterName.insert(0, "is"); return getterName.toString(); } }