Java Reflection Method Setter Get getSetterMethodByFieldName(String fieldName, Field field)

Here you can find the source of getSetterMethodByFieldName(String fieldName, Field field)

Description

get Setter Method By Field Name

License

LGPL

Declaration

public static Method getSetterMethodByFieldName(String fieldName, Field field) 

Method Source Code

//package com.java2s;
/**/* w  w w .j  a  va 2s  .c  om*/
 * CC-LGPL 2.1
 * http://creativecommons.org/licenses/LGPL/2.1/
 */

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Main {
    public static Method getSetterMethodByFieldName(String fieldName, Field field) {
        StringBuilder sb = new StringBuilder(fieldName.length() + 3);
        sb.append("set");
        sb.append(fieldName);
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        try {
            return field.getDeclaringClass().getDeclaredMethod(sb.toString(), field.getType());
        } catch (NoSuchMethodException e) {
            return null;
        }
    }
}

Related

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