Java Reflection Method Getter Get getGetterMethod(Class clazz, String propertyName)

Here you can find the source of getGetterMethod(Class clazz, String propertyName)

Description

get Getter Method

License

Open Source License

Declaration

public static Method getGetterMethod(Class<?> clazz, String propertyName) 

Method Source Code

//package com.java2s;
/**/*from ww w .ja va 2s . c o m*/
 * Copyright 2008 Autentia Real Business Solutions S.L.
 * 
 * This file is part of autentia-util.
 * 
 * autentia-util is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 * 
 * autentia-util 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.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with autentia-util. If not, see <http://www.gnu.org/licenses/>.
 */

import java.lang.reflect.Method;

public class Main {

    public static Method getGetterMethod(Class<?> clazz, String propertyName) {
        final String camelCase = propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
        String getterName = "get" + camelCase;
        Method getterMethod;
        try {
            getterMethod = clazz.getMethod(getterName);
        } catch (Exception e) {
            getterName = "is" + camelCase;
            try {
                getterMethod = clazz.getMethod(getterName);
            } catch (Exception e1) {
                return null;
            }
        }
        return getterMethod;
    }
}

Related

  1. getGetterMethod(Class beanClass, String property)
  2. getGetterMethod(Class c, String field)
  3. getGetterMethod(Class clazz, String fieldName)
  4. getGetterMethod(Class clazz, String methodNameWithoutGetPrefix)
  5. getGetterMethod(Class clazz, String name)
  6. getGetterMethod(String getterName, Object bean, Class returnType)
  7. getGetterMethodByProperty(String propertyName, Class beanClass, Class returnType)
  8. getGetterMethodForClass(Class cls, String beanName)
  9. getGetterMethodName(String fieldName, java.lang.Class fieldType)