Mega Code Archive
Gets the getters of a pojo as a map of String as key and Method as value
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
public class Util{
static final String GET = "get";
static final String IS = "is";
static final String SET = "set";
/**
* Gets the getters of a pojo as a map of {@link String} as key and
* {@link Method} as value.
*/
public static Map getGetterMethods(Class> pojoClass)
{
HashMap methods = new HashMap();
fillGetterMethods(pojoClass, methods);
return methods;
}
private static void fillGetterMethods(Class> pojoClass, Map baseMap)
{
if(pojoClass.getSuperclass()!=Object.class)
fillGetterMethods(pojoClass.getSuperclass(), baseMap);
Method[] methods = pojoClass.getDeclaredMethods();
for (int i=0;i