Java examples for java.lang.annotation:Class Annotation
get Annotation from annotated class
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { Object annotatedClass = "java2s.com"; Class annotation = String.class; System.out.println(getAnnotation(annotatedClass, annotation)); }// w w w . j a va 2 s . c o m public static <T> T getAnnotation(Object annotatedClass, Class<T> annotation) { Class screenType = annotatedClass.getClass(); return (T) screenType.getAnnotation(annotation); } }