Android Utililty Methods Class Field Find

List of utility methods to do Class Field Find

Description

The list of methods to do Class Field Find are organized into topic(s).

Method

FieldfindField(Class clazz, String fieldName)
Look up a field in a class and set it to accessible.
StringBuilder sb = new StringBuilder(clazz.getName());
sb.append('#');
sb.append(fieldName);
String fullFieldName = sb.toString();
if (fieldCache.containsKey(fullFieldName)) {
    Field field = fieldCache.get(fullFieldName);
    if (field == null)
        throw new NoSuchFieldError(fullFieldName);
...
FieldfindFieldRecursiveImpl(Class clazz, String fieldName)
find Field Recursive Impl
try {
    return clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
    while (true) {
        clazz = clazz.getSuperclass();
        if (clazz == null || clazz.equals(Object.class))
            break;
        try {
...
FieldfindFirstFieldByExactType(Class clazz, Class type)
Returns the first field of the given type in a class.
Class<?> clz = clazz;
do {
    for (Field field : clz.getDeclaredFields()) {
        if (field.getType() == type) {
            field.setAccessible(true);
            return field;
} while ((clz = clz.getSuperclass()) != null);
throw new NoSuchFieldError("Field of type " + type.getName()
        + " in class " + clazz.getName());
ObjectgetAdditionalStaticField(Class clazz, String key)
get Additional Static Field
return getAdditionalInstanceField(clazz, key);
Field[]getFields(Class cs)
get Fields
List<Field> fieldList = new ArrayList<Field>();
Class<?> c = cs;
while (c != null) {
    Field[] fields = c.getDeclaredFields();
    for (Field field : fields) {
        fieldList.add(field);
    c = c.getSuperclass();
...