当前位置:网站首页>Initial experience of annotation
Initial experience of annotation
2022-07-07 05:25:00 【Novice Xiaowang】
1. Definition notes
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Person {
String name() default "abc";
int age() default 20;
}
2. Using annotations
public class Student {
@Person(name = " king xx",age = 30)
public Object person;
}3. Handle comments
public class PersonUtils {
public static void getPersonInfo(Class<?> clazz){
for (Field declaredField : clazz.getDeclaredFields()) {
if (declaredField.isAnnotationPresent(Person.class)){
Person person = declaredField.getAnnotation(Person.class);
System.out.println("name:"+person.name()+"age"+person.age());
}
}
}
}4. test
PersonUtils.getPersonInfo(Student.class);5. result

边栏推荐
- 在米家、欧瑞博、苹果HomeKit趋势下,智汀如何从中脱颖而出?
- Torch optimizer small parsing
- As we media, what websites are there to download video clips for free?
- DJ-ZBS2漏电继电器
- y58.第三章 Kubernetes从入门到精通 -- 持续集成与部署(三一)
- ThinkPHP Association preload with
- NPDP产品经理认证,到底是何方神圣?
- Redis如何实现多可用区?
- Leetcode(46)——全排列
- Phenomenon analysis when Autowired annotation is used for list
猜你喜欢

《4》 Form

数字化创新驱动指南

利用OPNET进行网络指定源组播(SSM)仿真的设计、配置及注意点

基于 hugging face 预训练模型的实体识别智能标注方案:生成doccano要求json格式

【js组件】自定义select

Is the human body sensor easy to use? How to use it? Which do you buy between aqara green rice and Xiaomi

MySQL数据库学习(8) -- mysql 内容补充

What changes will PMP certification bring?

Leetcode(46)——全排列

Two person game based on bevy game engine and FPGA
随机推荐
AOSP ~Binder 通信原理 (一) - 概要
Two methods of thread synchronization
漏电继电器JOLX-GS62零序孔径Φ100
局部变量的数组初始化问题
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
Auto. JS get all app names of mobile phones
漏电继电器JD1-100
模拟线程通信
Knapsack problem unrelated to profit (depth first search)
Tencent cloud database public cloud market ranks top 2!
【opencv】图像形态学操作-opencv标记不同连通域的位置
Longest common subsequence (LCS) (dynamic programming, recursive)
CentOS 7.9 installing Oracle 21C Adventures
Is the human body sensor easy to use? How to use it? Which do you buy between aqara green rice and Xiaomi
Phenomenon analysis when Autowired annotation is used for list
背包问题(01背包,完全背包,动态规划)
DFS, BFS and traversal search of Graphs
EGR-20USCM接地故障继电器
Where is NPDP product manager certification sacred?
SQL injection cookie injection