get Annotation from annotated class - Java java.lang.annotation

Java examples for java.lang.annotation:Class Annotation

Description

get Annotation from annotated class

Demo Code


//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);
    }
}

Related Tutorials