print Annotations via Reflection - Java Reflection

Java examples for Reflection:Annotation

Description

print Annotations via Reflection

Demo Code


//package com.java2s;
import java.lang.annotation.Annotation;

import static java.lang.System.out;

public class Main {
    public static void printAnnotations(Class<?> c) {
        Annotation[] annotations = c.getAnnotations();
        out.format("Annotation => %n");

        if (annotations.length == 0) {
            out.format("  --%s", "No declared annotation found");
        } else {// w  ww.j  ava 2  s  . co  m
            for (Annotation a : annotations) {
                out.format("--%s", a.getClass().getCanonicalName());
            }
        }
        out.format("%n%n");
    }
}

Related Tutorials