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

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

Description

get Getter Method

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Method;

public class Main {

    public static Method getGetterMethod(Class<?> clazz, String name) {
        String methodName = convertToMehtodName("get", name);
        Method method = null;/*w  w w. ja  va2 s . c om*/
        try {
            method = clazz.getMethod(methodName);
        } catch (Exception e) {
            throw new RuntimeException("get method exception - ", e);
        }
        return method;
    }

    public static String convertToMehtodName(String getterOrSetter, String name) {
        String methodName = "";
        if (name != null && !name.equals("")) {
            String first = name.substring(0, 1);
            methodName = getterOrSetter + first.toUpperCase();
            if (name.length() > 1) {
                methodName = methodName + name.substring(1);
            }
        }
        return methodName;
    }
}

Related

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