Java Reflection Method Setter Get getSetterMethod(String setterName, Object bean, Class setterParamType)

Here you can find the source of getSetterMethod(String setterName, Object bean, Class setterParamType)

Description

get Setter Method

License

Open Source License

Declaration

public static Method getSetterMethod(String setterName, Object bean, Class<?> setterParamType) 

Method Source Code

//package com.java2s;
/*/*from w  ww  .  ja  v a 2s .  c o m*/
   Milyn - Copyright (C) 2006 - 2010
    
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License (version 2.1) as published by the Free Software
   Foundation.
    
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
   See the GNU Lesser General Public License for more details:
   http://www.gnu.org/licenses/lgpl.txt
*/

import java.lang.reflect.Method;

public class Main {
    public static Method getSetterMethod(String setterName, Object bean, Class<?> setterParamType) {
        return getSetterMethod(setterName, bean.getClass(), setterParamType);
    }

    public static Method getSetterMethod(String setterName, Class beanclass, Class<?> setterParamType) {
        Method[] methods = beanclass.getMethods();

        for (Method method : methods) {
            if (method.getName().equals(setterName)) {
                Class<?>[] params = method.getParameterTypes();
                if (params != null && params.length == 1 && params[0].isAssignableFrom(setterParamType)) {
                    return method;
                }
            }
        }

        return null;
    }
}

Related

  1. getSetterMethod(final Class clazz, final Class annotation, final String name, final String value)
  2. getSetterMethod(final Class clazz, final String propertyName, final Class type)
  3. getSetterMethod(final String methodName, final Class pojoClass, final Class attributeClass)
  4. getSetterMethod(Object obj, String name)
  5. getSetterMethod(String getterName, Class returnType, Class containingClass)
  6. getSetterMethodByFieldName(String fieldName, Field field)
  7. getSetterMethodByProperty(String propertyName, Class beanClass, Class setterParamType)
  8. getSetterMethodForClass(Class cls, String beanName, Class type)
  9. getSetterMethodFromGetter(final Method getter)