Here you can find the source of findAnnotationFromClass(Class> target, Class extends Annotation> annotation)
public static Annotation findAnnotationFromClass(Class<?> target, Class<? extends Annotation> annotation)
//package com.java2s; /*//from ww w . j av a 2s . c o m * Copyright (c) 2016, Quancheng-ec.com All right reserved. This software is the * confidential and proprietary information of Quancheng-ec.com ("Confidential * Information"). You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Quancheng-ec.com. */ import java.lang.annotation.Annotation; public class Main { public static Annotation findAnnotationFromClass(Class<?> target, Class<? extends Annotation> annotation) { for (Annotation targetAnnotation : target.getAnnotations()) { if (annotation.isAssignableFrom(targetAnnotation .annotationType())) { return targetAnnotation; } else { continue; } } return null; } }