Here you can find the source of getAnnotations(Enum> targetEnum, Class extends Annotation> targetAnnotationClass)
private static List<Annotation> getAnnotations(Enum<?> targetEnum, Class<? extends Annotation> targetAnnotationClass)
//package com.java2s; //License from project: Apache License import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.List; public class Main { private static List<Annotation> getAnnotations(Enum<?> targetEnum, Class<? extends Annotation> targetAnnotationClass) { Annotation[] allAnnotations; try {//from w ww . j a va 2 s . c o m allAnnotations = targetEnum.getClass().getField(targetEnum.name()).getAnnotations(); } catch (Exception e) { throw new IllegalStateException("It failed to get annotations. targetEnum = [" + targetEnum + "]", e); } List<Annotation> annotations = new ArrayList<Annotation>(); for (Annotation annotation : allAnnotations) { if (annotation.annotationType().getAnnotation(targetAnnotationClass) != null) { annotations.add(annotation); } } return annotations; } }