Java Utililty Methods Reflection Field Find

List of utility methods to do Reflection Field Find

Description

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

Method

FieldfindField(Class clazz, String name)
Attempt to find a Field field on the supplied Class with the supplied name .
return findField(clazz, name, null);
FieldfindField(Class clazz, String name)
find Field
return findField(clazz, name, null);
FieldfindField(Class clazz, String name)
searches for declared field in given class and all superclasses
if (clazz == null) {
    return null;
try {
    return clazz.getDeclaredField(name);
} catch (SecurityException e) {
    return null;
} catch (NoSuchFieldException e) {
...
FieldfindField(Class clazz, String name)
find Field
return findField(clazz, name, null);
FieldfindField(Class clazz, String name)
Find the field by name.
if (clazz == null)
    return null;
Field[] fields = clazz.getDeclaredFields();
if (fields.length != 0) {
    for (Field field : fields) {
        if (field.getName().equals(name))
            return field;
return findField(clazz.getSuperclass(), name);
FieldfindField(Class clazz, String name)
Attempt to find a Field field on the supplied Class with the supplied name.
Class<?> searchType = clazz;
while (searchType != null) {
    Field[] fields = searchType.getDeclaredFields();
    for (Field field : fields) {
        if ((name == null || name.equals(field.getName()))) {
            return field;
    searchType = searchType.getSuperclass();
return null;
FieldfindField(Class clazz, String name)
find Field
try {
    return clazz.getDeclaredField(name);
} catch (NoSuchFieldException e) {
    if (clazz.getSuperclass() != null) {
        return findField(clazz.getSuperclass(), name);
    return null;
FieldfindField(Class clazz, String name)
find Field
while (clazz != null) {
    Field f;
    try {
        f = clazz.getField(name);
        if (f != null)
            return f;
    } catch (NoSuchFieldException e) {
    try {
        f = clazz.getDeclaredField(name);
        if (f != null)
            return f;
    } catch (NoSuchFieldException e) {
    clazz = clazz.getSuperclass();
return null;
FieldfindField(Class clazz, String name)
Search a java.lang.reflect.Field given its class and name
return findField(clazz, name, null);
FieldfindField(Class clazz, String name)
find Field
Class<?> searchType = clazz;
while (!Object.class.equals(searchType) && searchType != null) {
    Field[] fields = searchType.getDeclaredFields();
    for (Field field : fields) {
        if ((name == null || name.equals(field.getName()))) {
            return field;
    searchType = searchType.getSuperclass();
return null;