Java Reflection Field Find findField(Class classToCheck, String propertyName)

Here you can find the source of findField(Class classToCheck, String propertyName)

Description

find Field

License

Open Source License

Declaration

public static Field findField(Class<?> classToCheck, String propertyName) 

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<?> classToCheck, String propertyName) {
        if (classToCheck == null || Object.class.equals(classToCheck)) {
            return null;
        }//from   w w w  .  j a va 2s .  c  om

        try {
            return classToCheck.getDeclaredField(propertyName);
        } catch (NoSuchFieldException nsfe) {
            return findField(classToCheck.getSuperclass(), propertyName);
        }

    }
}

Related

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