Java Reflection Method Getter Get getGetters(Object bean)

Here you can find the source of getGetters(Object bean)

Description

get Getters

License

Apache License

Declaration

public static List getGetters(Object bean) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import java.util.*;

import java.util.regex.Pattern;

public class Main {
    private static final Pattern PTN_GETTER = Pattern.compile("(get|is)[A-Z0-9].+");

    public static List getGetters(Object bean) {
        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);/*  ww w .  ja  va2  s  .  c  o  m*/
        }

        return list;
    }
}

Related

  1. getGetters(Class klass)
  2. getGetters(Class c)
  3. getGetters(Class clazz)
  4. getGetters(Class clazz)
  5. getGetters(final Class clazz)
  6. getGetters(Object obj)
  7. getGettersAndSetters(Object obj)
  8. getGetterSetterMethodsParameterType(Field f)
  9. getGetterShorthandName(Method method)