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

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

Description

find Field

License

Open Source License

Declaration

public static Field findField(Class<?> cls, String fieldName) 

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<?> cls, String fieldName) {
        Field f = null;/* www.j  a va 2s  .  co  m*/
        try {
            f = cls.getDeclaredField(fieldName);
        } catch (SecurityException ex) {
        } catch (NoSuchFieldException ex) {
        }
        if (f != null)
            return f;
        if (cls == Object.class || cls.getSuperclass() == null) {
            return null;
        }
        return findField(cls.getSuperclass(), fieldName);
    }
}

Related

  1. findField(Class clazz, String name)
  2. findField(Class clazz, String propName)
  3. findField(Class clazz, String targetName, Class targetType, boolean checkInheritance, boolean strictType)
  4. findField(Class cls, String fieldName)
  5. findField(Class cls, String fieldName)
  6. findField(Class currentClass, String fieldName)
  7. findField(Class inClass, String fieldName)
  8. findField(Class klass, String name)
  9. findField(Class pClass, String fieldName)