Here you can find the source of getAnnotationOfField(Field field, Class
public static <T extends Annotation> T getAnnotationOfField(Field field, Class<T> clazz)
//package com.java2s; //License from project: Open Source License import java.lang.annotation.Annotation; import java.lang.reflect.Field; public class Main { public static <T extends Annotation> T getAnnotationOfField(Field field, Class<T> clazz) { for (Annotation annotation : field.getDeclaredAnnotations()) { if (annotation.annotationType() == clazz) { return clazz.cast(annotation); }//w w w . j av a 2s. c o m } return null; } }