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(final Object instance, final String name)
find Field
try {
    return instance.getClass().getField(name);
} catch (NoSuchFieldException e) {
    return null;
FieldfindField(final Object src, final String fieldName)
find Field
Class<?> current = src.getClass();
Field field = null;
while (current != null && field == null) {
    field = getField(current, fieldName);
    current = current.getSuperclass();
if (field == null) {
    throw new NoSuchFieldException(src + " does not declare " + fieldName);
...
FieldfindField(final String className, final String fieldName)
Find field.
Field[] fields = fieldMapping.get(className);
for (Field field : fields) {
    if (field.getName().equals(fieldName)) {
        return field;
return null;
FieldfindField(Object container, String memberName)
find Field
Class cls = container.getClass();
try {
    Field fld = cls.getDeclaredField(memberName);
    return fld;
} catch (NoSuchFieldException e) {
    Field fld = cls.getDeclaredField("m_" + memberName);
    return fld;
FieldfindField(Object instance, String name)
Locates a given field anywhere in the class inheritance hierarchy.
for (Class<?> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
    try {
        Field field = clazz.getDeclaredField(name);
        if (!field.isAccessible()) {
            field.setAccessible(true);
        return field;
    } catch (NoSuchFieldException e) {
...
FieldfindField(Object obj, String beanPath)
find Field
try {
    if (beanPath.indexOf('.') > -1) {
        String name = beanPath.substring(0, beanPath.indexOf('.'));
        String path = beanPath.substring(beanPath.indexOf('.') + 1);
        Field field = obj.getClass().getDeclaredField(name);
        field.setAccessible(true);
        return findField(field.get(obj), path);
    } else if (obj == null) {
...
FieldfindField(Object obj, String fieldName)
Find a field in given object
Class<?> clazz = obj.getClass();
Field field = null;
while (clazz != null && field == null) {
    try {
        field = clazz.getDeclaredField(fieldName);
    } catch (NoSuchFieldException | SecurityException e) {
    clazz = clazz.getSuperclass();
...
FieldfindField(Object obj, String fieldName, Class type)
find Field
if (obj == null)
    return null;
Field theField = findField(obj, fieldName);
if (isFieldType(theField, type))
    return theField;
return null;
FieldfindField(Object obj, String name)
find Field
Class<?> cl = obj.getClass();
while (cl != null) {
    try {
        Field field = cl.getDeclaredField(name);
        if (!field.isAccessible()) {
            field.setAccessible(true);
        return field;
...
FieldfindField(Object object, String fieldName)
find Field
Field field = null;
Class<? extends Object> claz = object.getClass();
while (claz != null && field == null) {
    try {
        field = claz.getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
        claz = claz.getSuperclass();
if (field == null)
    throw new NoSuchFieldException("Can't find field with name " + fieldName);
return field;