Java Reflection Method Setter Get getSetter(Class clazz, Field field)

Here you can find the source of getSetter(Class clazz, Field field)

Description

get Setter

License

Apache License

Declaration

public static Method getSetter(Class<?> clazz, Field field) 

Method Source Code


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

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

public class Main {
    public static Method getSetter(Class<?> clazz, Field field) {
        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;//from  www .  j a  v a2 s .c om
        try {
            setMethod = clazz.getDeclaredMethod(setMethodName, fieldType);
        } catch (Exception e) {
        }
        return setMethod;
    }
}

Related

  1. getSetter(A instance, String strAttributeName, Class clazz)
  2. getSetter(Class _class, String fieldName)
  3. getSetter(Class clazz, String name)
  4. getSetter(Class clazz, Field field)
  5. getSetter(Class clazz, String property, Class type)
  6. getSetter(Class cls, final String fieldName)
  7. getSetter(final Class targetClass, final String propertyName)
  8. getSetter(final Class clazz, final String fieldName, final Class... fieldClass)