Java Reflection Method Getter Get getGetters(Object obj)

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

Description

get Getters

License

Open Source License

Declaration

public static List<Method> getGetters(Object obj) 

Method Source Code


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

import java.lang.reflect.*;
import java.util.*;

public class Main {
    public static List<Method> getGetters(Object obj) {
        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();
            if (!(name.startsWith("get") || name.startsWith("is") || name.startsWith("has")))
                continue;
            if (name.startsWith("has") && !(name.length() > 3 && Character.isUpperCase(name.charAt(3))))
                continue;
            if (name.equals("getClass"))
                continue;

            ret.add(method);/*w w w  .ja  v  a 2  s.co m*/
        }
        return ret;
    }
}

Related

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