Here you can find the source of getGetterMethod(String getterName, Object bean, Class> returnType)
public static Method getGetterMethod(String getterName, Object bean, Class<?> returnType)
//package com.java2s; /*/*from w ww . j a 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 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; } }