Java Utililty Methods Reflection Method Getter Get

List of utility methods to do Reflection Method Getter Get

Description

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

Method

StringgetGetterName(Method m)
Get getter name.
String name = m.getName();
if (name.startsWith("get") && (name.length() >= 4) && !m.getReturnType().equals(void.class)
        && (m.getParameterTypes().length == 0)) {
    return Character.toLowerCase(name.charAt(3)) + name.substring(4);
if (name.startsWith("is") && (name.length() >= 3)
        && (m.getReturnType().equals(boolean.class) || m.getReturnType().equals(Boolean.class))
        && (m.getParameterTypes().length == 0)) {
...
StringgetGetterName(Method method)
get Getter Name
String name = getDefaultPropertyName(method);
if (name == null)
    return null;
return "get" + name;
StringgetGetterName(Method mtd)
get Getter Name
String name = mtd.getName();
if (name.startsWith("get")) {
    return Character.toLowerCase(name.charAt(3)) + name.substring(4);
if (name.startsWith("is")) {
    return Character.toLowerCase(name.charAt(2)) + name.substring(3);
return null;
...
MethodgetGetterOrNull(Class clazz, String name, Class type)
get Getter Or Null
Class<?> beanClass = clazz;
String methodName = ((type.equals(Boolean.class) || type.equals(boolean.class)) ? "is" : "get") + name;
while (beanClass != null && !beanClass.equals(Object.class)) {
    try {
        return beanClass.getDeclaredMethod(methodName);
    } catch (SecurityException | NoSuchMethodException e) { 
    beanClass = beanClass.getSuperclass();
...
StringgetGetterPropertyName(Method getterMethod)
get Getter Property Name
if (getterMethod == null) {
    return null;
String name = getterMethod.getName();
if (name.startsWith("is")) {
    return name.substring(2);
} else {
    return name.substring(3);
...
ListgetGetters(Class c)
get Getters
List<Method> list = new ArrayList<Method>();
Method[] methods = c.getMethods();
for (int i = 0; i < methods.length; i++) {
    String name = methods[i].getName();
    if (!name.startsWith("get") || name.equals("getClass") || name.equals("getInstance")
            || methods[i].getParameterTypes().length != 0) {
        continue;
    list.add(methods[i]);
return list;
Method[]getGetters(Class clazz)
get Getters
List<Method> outM = new ArrayList<Method>();
for (Method m : clazz.getMethods()) {
    if (m.getParameterTypes().length == 0 && m.getName().startsWith("get") && m.getReturnType() != null) {
        outM.add(m);
return outM.toArray(new Method[outM.size()]);
SetgetGetters(Class klass)
get Getters
Set<Method> getters = new HashSet<Method>();
for (Method m : Arrays.asList(klass.getDeclaredMethods())) {
    if (m.getName().startsWith("get") && m.getParameterTypes().length == 0
            && !void.class.equals(m.getReturnType())) {
        getters.add(m);
return getters;
...
ListgetGetters(Class c)
Finds the getters of a class.
Method[] allMethods = c.getDeclaredMethods();
List<Method> getters = new LinkedList<>();
for (Method m : allMethods) {
    if (((m.getReturnType().equals(boolean.class) && m.getName().startsWith("is"))
            || m.getName().startsWith("get")) && m.getParameterTypes().length == 0) {
        getters.add(m);
return getters;
MapgetGetters(Class clazz)
get Getters
Map<String, Method> map = new LinkedHashMap<String, Method>();
Class<?> searchType = clazz;
while (searchType != null && searchType != Object.class) {
    Method[] methods = (searchType.isInterface()) ? new Method[0] : searchType.getDeclaredMethods();
    for (Method method : methods) {
        String name = method.getName();
        int modifiers = method.getModifiers();
        if (modifiers - Modifier.PUBLIC == 0 && method.getParameterTypes().length == 0) {
...