Here you can find the source of getMethod(Object bean, String propertyName)
Parameter | Description |
---|---|
bean | The bean |
propertyName | The property to get the getter for |
private static Method getMethod(Object bean, String propertyName)
//package com.java2s; /*/*from w ww . j a va 2 s .c o m*/ * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. */ import java.lang.reflect.Method; public class Main { /** * Return the named getter method on the bean or null if not found. * * @param bean The bean * @param propertyName The property to get the getter for * * @return the named getter method */ private static Method getMethod(Object bean, String propertyName) { final StringBuilder sb = new StringBuilder("get").append(Character.toUpperCase(propertyName.charAt(0))); if (propertyName.length() > 1) { sb.append(propertyName.substring(1)); } final String getterName = sb.toString(); for (Method m : bean.getClass().getMethods()) { if (getterName.equals(m.getName()) && m.getParameterTypes().length == 0) { return m; } } return null; } }