find Get Method - Android java.lang.reflect

Android examples for java.lang.reflect:Java Bean

Description

find Get Method

Demo Code


import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

public class Main{
    /**/*  www .java2  s  .  com*/
     * get methods should have no arguments, they should be written as java standards get<FieldName> e.g for fieldName identity getMethod's name should be getIdentity
     * 
     * @param clazz target class
     * @param fieldName field's name
     * @return getter method for specified field.
     * @throws NoSuchMethodException
     * @throws SecurityException
     */
    public static Method findGetMethod(Class<?> clazz, String fieldName)
            throws SecurityException, NoSuchMethodException {
        String methodName = "get" + fieldName.substring(0, 1).toUpperCase()
                + fieldName.substring(1);
        return clazz.getMethod(methodName);
    }
}

Related Tutorials