Java Utililty Methods Reflection Method Setter Get

List of utility methods to do Reflection Method Setter Get

Description

The list of methods to do Reflection Method Setter Get are organized into topic(s).

Method

MethodgetSetter(A instance, String strAttributeName, Class clazz)
Gets the setter.
return getMethod(PREFIX_SET, instance, strAttributeName, clazz);
MethodgetSetter(Class _class, String fieldName)
get Setter
return getSetter(gatherAllBeanFields(_class).get(fieldName));
MethodgetSetter(Class clazz, String name)
Get a setter with a given name from a class.
Method[] methods = clazz.getMethods();
Method setter = null;
for (int i = 0; i < methods.length; i++) {
    if (isSetter(methods[i]) && name.equals(methods[i].getName())) {
        setter = methods[i];
        break;
return setter;
MethodgetSetter(Class clazz, Field field)
get Setter
Method setter = clazz.getMethod(getSetterName(field), field.getType());
if (!setter.getReturnType().equals(void.class)) {
    throw new NoSuchMethodException();
return setter;
MethodgetSetter(Class clazz, Field field)
get Setter
Class<?> fieldType = field.getType();
String filedName = field.getName();
String firstLetter = filedName.substring(0, 1).toUpperCase();
String setMethodName = "set" + firstLetter + filedName.substring(1);
Method setMethod = null;
try {
    setMethod = clazz.getDeclaredMethod(setMethodName, fieldType);
} catch (Exception e) {
...
MethodgetSetter(Class clazz, String property, Class type)
get Setter
String setterName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1);
try {
    Method method = clazz.getDeclaredMethod(setterName, type);
    return method;
} catch (NoSuchMethodException e) {
    throw new IllegalArgumentException("no setter found for property '" + property + "'", e);
MethodgetSetter(Class cls, final String fieldName)
get Setter
for (final Method method : cls.getMethods()) {
    if (method.getName().equalsIgnoreCase("set" + fieldName) && method.getParameters().length == 1) {
        if (!method.isAccessible()) {
            method.setAccessible(true);
        return method;
return null;
MethodgetSetter(final Class targetClass, final String propertyName)
get Setter
String setterName = "set" + Character.toUpperCase(propertyName.charAt(0));
if (setterName.length() > 1)
    setterName += propertyName.substring(1);
final Method[] methods = targetClass.getMethods();
for (Method m : methods) {
    if (m.getName().equals(setterName) && m.getParameterTypes().length == 1)
        return m;
return null;
MethodgetSetter(final Class clazz, final String fieldName, final Class... fieldClass)
get Setter
final String methodName = "set" + capitalize(fieldName);
try {
    final Method method = clazz.getDeclaredMethod(methodName, fieldClass);
    method.setAccessible(true);
    return method;
} catch (SecurityException | NoSuchMethodException e) {
return null;
...
MethodgetSetter(final Class clz, final String propertyName, final Class propertyClass)
get Setter
final Class<?> setterArgs[] = new Class[1];
setterArgs[0] = propertyClass;
final String setterName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
return clz.getMethod(setterName, setterArgs);