java 自定义注解

package com.tedu.in;

import java.lang.reflect.Field;

public class Test {
    public static void main(String[] args) {
        Class<User> user = User.class;
        Field[] fs = user.getDeclaredFields();
        for (Field f : fs) {
        // 获取属性上是否存在制定的注解
            inter annotation = f.getAnnotation(inter.class);
            // 判断annotation是否为空
            if (annotation!=null){
                // 获取注解的内容
                String value = annotation.value();
                System.out.println(annotation.value());
            }else {
                System.out.println("没有找到制定的注解");
            }
        }
    }
}
posted @ 2022-11-10 21:08  竹石2020  阅读(7)  评论(0编辑  收藏  举报