Here you can find the source of getAnnotation(final Class> type, final Class
Parameter | Description |
---|---|
type | type to examine |
annotation | annotation to search |
T | annotation type |
public static <T extends Annotation> T getAnnotation(final Class<?> type, final Class<T> annotation)
//package com.java2s; //License from project: Open Source License import java.lang.annotation.Annotation; import java.lang.reflect.Modifier; public class Main { /**//from w w w. ja v a 2s .c o m * @param type type to examine * @param annotation annotation to search * @param <T> annotation type * @return found annotation or null */ public static <T extends Annotation> T getAnnotation(final Class<?> type, final Class<T> annotation) { T res = null; if (!Modifier.isAbstract(type.getModifiers())) { Class<?> supertype = type; while (supertype != null && Object.class != supertype) { if (supertype.isAnnotationPresent(annotation)) { res = supertype.getAnnotation(annotation); break; } supertype = supertype.getSuperclass(); } } return res; } }