Java Utililty Methods Reflection Method Getter Get

List of utility methods to do Reflection Method Getter Get

Description

The list of methods to do Reflection Method Getter Get are organized into topic(s).

Method

MapgetGetters(Class clazz)
get a map of public getters (propertyName -> Method)
Map<String, Method> getters = new HashMap<String, Method>();
Method[] methods = clazz.getMethods();
for (Method method : methods) {
    String methodName = method.getName();
    if (method.getParameterTypes().length == 0) {
        if (methodName.startsWith("get") && methodName.length() > 3) {
            String propertyName = methodName.substring(3, 4).toLowerCase();
            if (methodName.length() > 4) {
...
MapgetGetters(final Class clazz)
Returns a Map of getter methods of the given class.

The key of the map contains the name of the attribute that can be accessed by the getter, the value the getter itself (an instance of java.lang.reflect.Method).

final Map<String, Method> accessors = new HashMap<String, Method>();
final Method[] methods = clazz.getMethods();
for (Method method : methods) {
    String name;
    String methodName;
    methodName = method.getName();
    if (!methodName.startsWith("get")) {
        continue;
...
ListgetGetters(Object bean)
get Getters
ArrayList list = new ArrayList();
Method[] methods = bean.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
    Method method = methods[i];
    if (PTN_GETTER.matcher(method.getName()).matches() && !"getClass".equals(method.getName())
            && method.getParameterTypes().length == 0 && Modifier.isPublic(method.getModifiers())
            && !Modifier.isStatic(method.getModifiers()))
        list.add(method);
...
ListgetGetters(Object obj)
get Getters
List<Method> ret = new ArrayList<Method>();
for (Method method : obj.getClass().getMethods()) {
    int mod = method.getModifiers();
    if (Modifier.isStatic(mod) || !Modifier.isPublic(mod))
        continue;
    if (method.getParameterTypes().length != 0)
        continue;
    String name = method.getName();
...
Method[]getGettersAndSetters(Object obj)
get Getters And Setters
Method[] methods, superMethods = null;
methods = obj.getClass().getDeclaredMethods();
Package pkg = obj.getClass().getPackage();
if (null != pkg && pkg.toString().indexOf("ome.model2") > -1) {
    superMethods = obj.getClass().getSuperclass().getDeclaredMethods();
List goodMethods = checkGettersAndSetters(methods);
goodMethods.addAll(checkGettersAndSetters(superMethods));
...
ClassgetGetterSetterMethodsParameterType(Field f)
get Getter Setter Methods Parameter Type
Method getter = prepareGetterMethod(f);
if (getter == null) {
    return null;
Class rt = getter.getReturnType();
Method setter = prepareSetterMethod(f, rt);
return (setter == null) ? null : rt;
StringgetGetterShorthandName(Method method)
get Getter Shorthand Name
if (!isGetter(method)) {
    return method.getName();
String name = method.getName();
if (name.startsWith("get")) {
    name = name.substring(3);
    name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
} else if (name.startsWith("is")) {
...
ListgetGettersMethods(Object object)
get Getters Methods
List<Method> getters = new ArrayList<>();
Method[] methods = object.getClass().getMethods();
for (Method method : methods) {
    String methodName = method.getName();
    if ((methodName.startsWith("get") || methodName.startsWith("is")) && !methodName.equals("getClass")) {
        getters.add(method);
return getters;
ObjectgetGetterValue(Method method, Object o)
get Getter Value
try {
    return method.invoke(o, null);
} catch (Exception e) {
return null;
MethodgetGetterWithPrefix(final Class target, final String property, final String prefix)
Internal method used by the getGetter method to try the different possible prefixes 'get', 'has' and 'is'.
String name = prefix + Character.toUpperCase(property.charAt(0));
if (property.length() > 1)
    name = name + property.substring(1);
return getMethod(target, name);