集册 Java实例教程 通过反射打印注释

通过反射打印注释

欢马劈雪     最近更新时间:2020-01-02 10:19:05

423
通过反射打印注释


//package com.nowjava;

import java.lang.annotation.Annotation;/**来自 N  o w  J a v a . c o m**/


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 {

            for (Annotation a : annotations) {

                out.format(
展开阅读全文