Here you can find the source of getAnnotation(Annotation[] annotations, Class
@SuppressWarnings("unchecked") public static <T extends Annotation> Optional<T> getAnnotation(Annotation[] annotations, Class<T> annotationClazz)
//package com.java2s; //License from project: Apache License import java.lang.annotation.Annotation; import java.util.Optional; public class Main { @SuppressWarnings("unchecked") public static <T extends Annotation> Optional<T> getAnnotation(Annotation[] annotations, Class<T> annotationClazz) { for (Annotation a : annotations) { if (annotationClazz.isAssignableFrom(a.getClass())) { return Optional.of((T) a); }/*from w w w . ja va 2s . co m*/ } return Optional.empty(); } }