Here you can find the source of getAnnotationClass(Class> clazz, Class
Parameter | Description |
---|---|
clazz | a class, which classloader will be used |
annotation | an annotation to load |
T | annotation parameter |
public static <T extends Annotation> Class<T> getAnnotationClass(Class<?> clazz, Class<T> annotation)
//package com.java2s; //License from project: Open Source License import java.lang.annotation.Annotation; public class Main { /**//from w ww .j ava2s .com * Loads annotation class, using class loader of the specified class. * * @param clazz a class, which classloader will be used * @param annotation an annotation to load * @param <T> annotation parameter * @return annotation class, loaded using class loader of the given class */ public static <T extends Annotation> Class<T> getAnnotationClass(Class<?> clazz, Class<T> annotation) { ClassLoader clazzClassLoader = clazz.getClassLoader(); ClassLoader annotationClassLoader = annotation.getClassLoader(); if (null != clazzClassLoader && !clazzClassLoader.equals(annotationClassLoader)) { try { return (Class<T>) clazzClassLoader.loadClass(annotation.getName()); } catch (ClassNotFoundException e) { // if the classloader for the given class cannot find the annotation class // then the given annotation class will be returned } } return annotation; } }