Java Reflection Field Find findField(Object obj, String name)

Here you can find the source of findField(Object obj, String name)

Description

find Field

License

Open Source License

Declaration

private static Field findField(Object obj, String name) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Field;

public class Main {
    private static Field findField(Object obj, String name) {
        Class<?> cl = obj.getClass();
        while (cl != null) {
            try {
                Field field = cl.getDeclaredField(name);
                if (!field.isAccessible()) {
                    field.setAccessible(true);
                }/*  w w w. j  a  v  a2 s  .  co m*/
                return field;
            } catch (NoSuchFieldException e) {
                cl = cl.getSuperclass();
            }
        }
        throw new IllegalArgumentException("Field " + name + " not found in " + obj.getClass().getName());
    }
}

Related

  1. findField(Object container, String memberName)
  2. findField(Object instance, String name)
  3. findField(Object obj, String beanPath)
  4. findField(Object obj, String fieldName)
  5. findField(Object obj, String fieldName, Class type)
  6. findField(Object object, String fieldName)
  7. findField(Object object, String name, Class klass)
  8. findField(Object propertyId, Class classOfItem)
  9. findField(Object target, Class type)