Java Reflection Method Setter Get getSetters(Class c)

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

Description

Finds the setters of a class.

License

Open Source License

Parameter

Parameter Description
c The class.

Return

The setters of the class.

Declaration

public static List<Method> getSetters(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   w ww .  java  2  s  .co  m
     * Finds the setters of a class.
     *
     * @param c
     *          The class.
     * @return The setters of the class.
     */
    public static List<Method> getSetters(Class<?> c) {
        return getSetters(c, false);
    }

    private static List<Method> getSetters(Class<?> c, boolean flag) {
        Method[] allMethods = c.getDeclaredMethods();
        List<Method> setters = new LinkedList<>();
        for (Method m : allMethods) {
            Class<?>[] types = m.getParameterTypes();
            if (m.getName().startsWith("set") && types.length == (flag ? 2 : 1)) {

                if ((flag && types[1].equals(boolean.class)) || !flag) {
                    setters.add(m);
                }
            }
        }
        return setters;
    }
}

Related

  1. getSetterOrGetter(Class clazz, String name, boolean isSetter)
  2. getSetters(Class clazz)
  3. getSetters(Class clazz)
  4. getSetters(Class klass)
  5. getSetters(Class klass)
  6. getSetters(Class clazz)
  7. getSetters(Class clazz)
  8. getSetters(Class klass)
  9. getSetters(Object obj)