Java Reflection Method Setter Get getSetter(Class cls, final String fieldName)

Here you can find the source of getSetter(Class cls, final String fieldName)

Description

get Setter

License

Open Source License

Declaration

public static <T> Method getSetter(Class<T> cls, final String fieldName) 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    public static <T> Method getSetter(Class<T> cls, final String fieldName) {
        for (final Method method : cls.getMethods()) {
            // method must start with "set" and have only one parameter, matching the
            // specified fieldType
            if (method.getName().equalsIgnoreCase("set" + fieldName) && method.getParameters().length == 1) {
                if (!method.isAccessible()) {
                    method.setAccessible(true);
                }/*from  w  w  w  .  j a v  a 2  s .c  o m*/

                return method;
            }
        }

        return null;
    }
}

Related

  1. getSetter(Class _class, String fieldName)
  2. getSetter(Class clazz, String name)
  3. getSetter(Class clazz, Field field)
  4. getSetter(Class clazz, Field field)
  5. getSetter(Class clazz, String property, Class type)
  6. getSetter(final Class targetClass, final String propertyName)
  7. getSetter(final Class clazz, final String fieldName, final Class... fieldClass)
  8. getSetter(final Class clz, final String propertyName, final Class propertyClass)
  9. getSetter(final Object o, final String fieldName)