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

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

Description

find Field

License

Apache License

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Field;

public class Main {
    public static Field findField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
        Class<?> current = clazz;
        do {//w w  w .j  av  a  2 s .  co  m
            try {
                return current.getDeclaredField(fieldName);
            } catch (Exception e) {
            }
        } while ((current = current.getSuperclass()) != null);
        throw new NoSuchFieldException(fieldName);
    }
}

Related

  1. findField(Class clazz, final String field)
  2. findField(Class clazz, String field)
  3. findField(Class clazz, String field, Class type, int index)
  4. findField(Class clazz, String fieldName)
  5. findField(Class clazz, String fieldName)
  6. findField(Class clazz, String fieldName)
  7. findField(Class clazz, String fieldName)
  8. findField(Class clazz, String fname, boolean isSearchSuperclass)
  9. findField(Class clazz, String name)