Java Reflection Method Getter Get getGetters(Class c)

Here you can find the source of getGetters(Class c)

Description

Finds the getters of a class.

License

Open Source License

Parameter

Parameter Description
c The class.

Return

The getters of the class.

Declaration

public static List<Method> getGetters(Class<?> c) 

Method Source Code

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

import java.lang.reflect.Method;

import java.util.LinkedList;
import java.util.List;

public class Main {
    /**//from   ww w  .  jav  a2  s .c  o m
     * Finds the getters of a class.
     *
     * @param c
     *          The class.
     * @return The getters of the class.
     */
    public static List<Method> getGetters(Class<?> c) {
        Method[] allMethods = c.getDeclaredMethods();
        List<Method> getters = new LinkedList<>();
        for (Method m : allMethods) {
            if (((m.getReturnType().equals(boolean.class) && m.getName().startsWith("is"))
                    || m.getName().startsWith("get")) && m.getParameterTypes().length == 0) {

                getters.add(m);
            }
        }
        return getters;
    }
}

Related

  1. getGetterOrNull(Class clazz, String name, Class type)
  2. getGetterPropertyName(Method getterMethod)
  3. getGetters(Class c)
  4. getGetters(Class clazz)
  5. getGetters(Class klass)
  6. getGetters(Class clazz)
  7. getGetters(Class clazz)
  8. getGetters(final Class clazz)
  9. getGetters(Object bean)