当前位置:网站首页>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

边栏推荐
- When deleting a file, the prompt "the length of the source file name is greater than the length supported by the system" cannot be deleted. Solution
- Longest palindrome substring (dynamic programming)
- What changes will PMP certification bring?
- Clickhouse (03) how to install and deploy Clickhouse
- Two person game based on bevy game engine and FPGA
- 阿里云的神龙架构是怎么工作的 | 科普图解
- 【最佳网页宽度及其实现】「建议收藏」
- MySQL数据库学习(7) -- pymysql简单介绍
- Is PMP really useful?
- 2039: [Bluebridge cup 2022 preliminaries] Li Bai's enhanced version (dynamic planning)
猜你喜欢

Longest palindrome substring (dynamic programming)

Window scheduled tasks

QT simple layout box model with spring

Life experience of an update statement
[email protected] Mapping relatio"/>Why JSON is used for calls between interfaces, how fastjson is assigned, fastjson 1.2 [email protected] Mapping relatio

LabVIEW is opening a new reference, indicating that the memory is full

window定时计划任务

拿到PMP认证带来什么改变?

ThinkPHP关联预载入with

利用OPNET进行网络单播(一服务器多客户端)仿真的设计、配置及注意点
随机推荐
做自媒体视频剪辑,专业的人会怎么寻找背景音乐素材?
Harmonyos fourth training
高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏
Dynamically generate tables
AOSP ~binder communication principle (I) - Overview
Most commonly used high number formula
MySQL数据库学习(8) -- mysql 内容补充
人体传感器好不好用?怎么用?Aqara绿米、小米之间到底买哪个
Knapsack problem unrelated to profit (depth first search)
Leetcode(417)——太平洋大西洋水流问题
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
模拟线程通信
2039: [蓝桥杯2022初赛] 李白打酒加强版 (动态规划)
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
Leetcode (417) -- Pacific Atlantic current problem
window定时计划任务
创始人负债10亿,开课吧即将“下课”?
2039: [Bluebridge cup 2022 preliminaries] Li Bai's enhanced version (dynamic planning)
Why JSON is used for calls between interfaces, how fastjson is assigned, fastjson 1.2 [email protected] Mapping relatio
MySQL数据库学习(7) -- pymysql简单介绍