Java Reflection Method Setter Get getSetterMethods(Class clazz)

Here you can find the source of getSetterMethods(Class clazz)

Description

get Setter Methods

License

Open Source License

Declaration

public static List<Method> getSetterMethods(Class<?> clazz) 

Method Source Code


//package com.java2s;
/*//  www.  j a v a2  s. co  m
    
Copyright (c) 2009-2011, AOL Inc.
All rights reserved.
    
This code is licensed under a BSD license.
    
Howard Uman
    
*/

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
    public static List<Method> getSetterMethods(Class<?> clazz) {
        Method[] methods = clazz.getMethods();
        ArrayList<Method> setterMethods = new ArrayList<Method>(methods.length);

        for (Method method : methods) {
            // remove: 
            // non-public methods
            // methods with not-1 parameters
            // methods that do not begin with the "set" convention
            if (!Modifier.isPublic(method.getModifiers()) || (method.getParameterTypes().length != 1)
                    || !method.getName().startsWith("set")) {
                continue;
            }

            setterMethods.add(method);
        }

        return Collections.unmodifiableList(setterMethods);
    }
}

Related

  1. getSetterMethodByFieldName(String fieldName, Field field)
  2. getSetterMethodByProperty(String propertyName, Class beanClass, Class setterParamType)
  3. getSetterMethodForClass(Class cls, String beanName, Class type)
  4. getSetterMethodFromGetter(final Method getter)
  5. getSetterMethods(Class clazz)
  6. getSetterMethods(Class clazz)
  7. getSetterMethods(Class objectType)
  8. getSetterMethods(Class pojoClass)
  9. getSetterMethods(final Class clazz)