Java Reflection Method Getter Get getGetterFromCache(Class clazz)

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

Description

get Getter From Cache

License

Open Source License

Declaration

public static List<Method> getGetterFromCache(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>> getterCache = new ConcurrentHashMap<>();

    public static List<Method> getGetterFromCache(Class clazz) {
        List<Method> methods = getterCache.get(clazz);
        if (methods == null) {
            methods = new ArrayList<>();
            for (Method method : clazz.getDeclaredMethods()) {
                String name = method.getName();
                if (method.getParameterTypes().length == 0) {
                    if (name.startsWith("get")) {
                        methods.add(method);
                    }/*w  w w.  j  a v  a2  s  . c o  m*/
                    if (name.startsWith("is")) {
                        methods.add(method);
                    }
                }
            }
            getterCache.put(clazz, methods);
        }
        return methods;
    }
}

Related

  1. getGetterAttributeType(Method m)
  2. getGetterFieldName(Method method)
  3. getGetterFields(final Class clazz)
  4. getGetterFor(Field field)
  5. getGetterFor(Object obj, Field field, Class objClass)
  6. getGetterFromProperty(Class clazz, String property)
  7. getGetterMethod(Class containingClass, String propertyName)
  8. getGetterMethod(Class type, String property)
  9. getGetterMethod(Class beanClass, String property)