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

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

Description

find Field

License

Apache License

Declaration

private static Field findField(Class objectClass, String fieldName) 

Method Source Code


//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.lang.reflect.Field;

public class Main {
    private static Field findField(Class objectClass, String fieldName) {

        Class cursor = objectClass;

        while (cursor != null) {
            try {
                return cursor.getDeclaredField(fieldName);
            } catch (NoSuchFieldException ex) {
                // Ignore.
            }/* ww  w.  j a  v a  2  s . c  o m*/

            cursor = cursor.getSuperclass();
        }

        throw new RuntimeException(
                String.format("Class %s does not contain a field named '%s'.", objectClass.getName(), fieldName));
    }
}

Related

  1. findField(Class clazz, String name)
  2. findField(Class clazz, String name)
  3. findField(Class clazz, String name)
  4. findField(Class clazz, String name)
  5. findField(Class cls, String name)
  6. findField(Class type, String fieldName)
  7. findField(Class c, String name)
  8. findField(Class c, String property, Class propertyType)
  9. findField(Class cl, String fieldName)