Java Reflection Field Find findField(Class cl, String fieldName)

Here you can find the source of findField(Class cl, String fieldName)

Description

find Field

License

Open Source License

Declaration

public static Field findField(Class<?> cl, String fieldName) throws NoSuchFieldException 

Method Source Code


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

import java.lang.reflect.Field;

import java.util.Objects;

public class Main {
    public static Field findField(Class<?> cl, String fieldName) throws NoSuchFieldException {
        try {//from   w w  w.  ja va2s  .  c  o  m
            return cl.getDeclaredField(fieldName);
        } catch (SecurityException sex) {
            return null;
        } catch (NoSuchFieldException e) {
            if (Objects.equals(cl, Object.class)) {
                throw e;
            }
            return findField(cl.getSuperclass(), fieldName);
        }
    }
}

Related

  1. findField(Class cls, String name)
  2. findField(Class objectClass, String fieldName)
  3. findField(Class type, String fieldName)
  4. findField(Class c, String name)
  5. findField(Class c, String property, Class propertyType)
  6. findField(Class classToCheck, String propertyName)
  7. findField(Class claz, String... names)
  8. findField(Class clazz, final String field)
  9. findField(Class clazz, String field)