Java Reflection Method Setter Get getSetterFromCache(Class clazz)

Here you can find the source of getSetterFromCache(Class clazz)

Description

get Setter From Cache

License

Open Source License

Declaration

public static List<Method> getSetterFromCache(Class clazz) 

Method Source Code

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

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Main {
    private static final Map<Class, List<Method>> setterCache = new ConcurrentHashMap<>();

    public static List<Method> getSetterFromCache(Class clazz) {
        List<Method> methods = setterCache.get(clazz);
        if (methods == null) {
            methods = new ArrayList<>();
            for (Method method : clazz.getDeclaredMethods()) {
                String name = method.getName();
                if (name.startsWith("set") && method.getParameterTypes().length == 1 && name.length() > 3) {
                    methods.add(method);
                }//from  ww  w  .  j  av  a 2 s.c o  m
            }
            setterCache.put(clazz, methods);
        }
        return methods;
    }
}

Related

  1. getSetter(String propertyName, Class clazz, Class arg)
  2. getSetter(String s)
  3. getSetterAttributeType(Method m)
  4. getSetterFieldName(Method method)
  5. getSetterForGetter(Method[] methods, Method getter)
  6. getSetterMap(Class cls)
  7. getSetterMethod(Class beanClass, String fieldName, List supportedTypes)
  8. getSetterMethod(Class c, String methodName)
  9. getSetterMethod(Class containingClass, Class propertyType, String propertyName)