Java Reflection Method Setter Get getSetter(final Class clazz, final String fieldName, final Class... fieldClass)

Here you can find the source of getSetter(final Class clazz, final String fieldName, final Class... fieldClass)

Description

get Setter

License

Apache License

Declaration

public static Method getSetter(final Class<?> clazz, final String fieldName, final Class<?>... fieldClass) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

public class Main {

    public static Method getSetter(final Class<?> clazz, final String fieldName, final Class<?>... fieldClass) {

        final String methodName = "set" + capitalize(fieldName);

        // private / protected method
        try {//from ww w  .j  a  va  2s  . com
            final Method method = clazz.getDeclaredMethod(methodName, fieldClass);
            method.setAccessible(true);
            return method;
        } catch (SecurityException | NoSuchMethodException e) {
        }

        return null;
    }

    public static String capitalize(final String str) {
        final int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }

        return new StringBuilder(strLen).append(String.valueOf(str.charAt(0)).toUpperCase())
                .append(str.substring(1)).toString();
    }
}

Related

  1. getSetter(Class clazz, Field field)
  2. getSetter(Class clazz, Field field)
  3. getSetter(Class clazz, String property, Class type)
  4. getSetter(Class cls, final String fieldName)
  5. getSetter(final Class targetClass, final String propertyName)
  6. getSetter(final Class clz, final String propertyName, final Class propertyClass)
  7. getSetter(final Object o, final String fieldName)
  8. getSetter(Method m)
  9. getSetter(Object instance, String methodName)