Java Reflection Method Getter Get getGetterMethod(Class c, String field)

Here you can find the source of getGetterMethod(Class c, String field)

Description

get Getter Method

License

Open Source License

Declaration

public static Method getGetterMethod(Class<?> c, String field) 

Method Source Code

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

import java.lang.reflect.Method;

import static java.util.Locale.ENGLISH;

public class Main {
    public static Method getGetterMethod(Class<?> c, String field) {
        try {/*from  w  w w .  j a va 2s  .  com*/
            return c.getMethod(getterMethod(field));
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }

    public static String getterMethod(String field) {
        return "get" + capitalize(field);
    }

    public static String capitalize(String s) {
        if (s == null || s.length() == 0) {
            return s;
        }
        return s.substring(0, 1).toUpperCase(ENGLISH) + s.substring(1);
    }
}

Related

  1. getGetterFromCache(Class clazz)
  2. getGetterFromProperty(Class clazz, String property)
  3. getGetterMethod(Class containingClass, String propertyName)
  4. getGetterMethod(Class type, String property)
  5. getGetterMethod(Class beanClass, String property)
  6. getGetterMethod(Class clazz, String fieldName)
  7. getGetterMethod(Class clazz, String methodNameWithoutGetPrefix)
  8. getGetterMethod(Class clazz, String name)
  9. getGetterMethod(Class clazz, String propertyName)