Java Reflection Field Find findField(Class classBeFind, String name)

Here you can find the source of findField(Class classBeFind, String name)

Description

find Field

License

Open Source License

Declaration

public static Field findField(Class classBeFind, String name) 

Method Source Code


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

import java.lang.reflect.Field;

public class Main {

    public static Field findField(Class classBeFind, String name) {
        Field field = null;//w  w  w .  j a  v a  2s.c  om
        while (true) {
            try {
                field = classBeFind.getDeclaredField(name);
            } catch (Exception e) {
                field = null;
            }
            if (field != null) {
                return field;
            }
            classBeFind = classBeFind.getSuperclass();
            if (classBeFind == null) {
                return null;
            }
        }
    }
}

Related

  1. findField(@Nonnull Class clazz, @Nonnull String name, Class type)
  2. findField(Class aClass, String aFieldName)
  3. findField(Class c, Class fieldtype)
  4. findField(Class c, String fieldName)
  5. findField(Class classType, String fieldName, Class fieldType)
  6. findField(Class clazz, Class type, String name)
  7. findField(Class clazz, String fieldName)
  8. findField(Class clazz, String fieldName)