Java Reflection Field Find findFieldEx(Class type, Class annotationClass)

Here you can find the source of findFieldEx(Class type, Class annotationClass)

Description

find Field Ex

License

Open Source License

Declaration

private static <T extends Annotation> Field findFieldEx(Class<?> type, Class<T> annotationClass) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

public class Main {
    private static <T extends Annotation> Field findFieldEx(Class<?> type, Class<T> annotationClass) {
        for (Field field : type.getDeclaredFields()) {
            if (field.getAnnotation(annotationClass) != null) {
                return field;
            }/*from  w  ww.  java  2  s  .c o  m*/
        }
        throw new IllegalArgumentException("Specific ".concat(type.getName()).concat(" must have annotation ")
                .concat(annotationClass.getName()));
    }
}

Related

  1. findField(String name, Class c)
  2. findField(String name, Object o)
  3. findField(String string, Class clazz)
  4. findField0(Class clazz, String name, String methodName)
  5. findFieldByName(Class owner, String name)
  6. findFieldFromClassHierarchy(Class clazz, String fieldName)
  7. findFieldFromGetter(Class clazz, Method method)
  8. findFieldIn(Class type, String name)
  9. findFieldInClass(Class clazz, String fieldName)