Java Reflection Field Find findFieldIncludeSuperclass(String fieldName, Class clazz)

Here you can find the source of findFieldIncludeSuperclass(String fieldName, Class clazz)

Description

find Field Include Superclass

License

Open Source License

Declaration

protected static Field findFieldIncludeSuperclass(String fieldName, Class<?> clazz) 

Method Source Code

//package com.java2s;
/*//from  w w  w. ja  v  a 2s . c om
 * Copyright 1999-2004 Alibaba.com All right reserved. This software is the confidential and proprietary information of
 * Alibaba.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with Alibaba.com.
 */

import java.lang.reflect.Field;

public class Main {
    protected static Field findFieldIncludeSuperclass(String fieldName, Class<?> clazz) {
        Field retValue = null;
        try {
            retValue = clazz.getDeclaredField(fieldName);
        } catch (NoSuchFieldException e) {
            clazz = clazz.getSuperclass();
            if (clazz != null) {
                retValue = findFieldIncludeSuperclass(fieldName, clazz);
            }
        }
        return retValue;
    }
}

Related

  1. findFieldFromClassHierarchy(Class clazz, String fieldName)
  2. findFieldFromGetter(Class clazz, Method method)
  3. findFieldIn(Class type, String name)
  4. findFieldInClass(Class clazz, String fieldName)
  5. findFieldInClassHierarchy(Class clazz, String fieldName)
  6. findFieldInternal(Class currentClass, Class annotation, Set fields)
  7. findFieldOfBean(Object bean, String fieldName)
  8. findFieldOfTypeInClass(final Class source, final Class type)
  9. findFieldRecursively(Class c, String fieldName)