当前位置:网站首页>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
边栏推荐
- Linkedblockingqueue source code analysis - initialization
- Two methods of thread synchronization
- If you want to choose some departments to give priority to OKR, how should you choose pilot departments?
- 项目经理如何凭借NPDP证书逆袭?看这里
- Auto. JS get all app names of mobile phones
- Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
- 全链路压测:影子库与影子表之争
- The sooner you understand the four rules of life, the more blessed you will be
- 拿到PMP认证带来什么改变?
- AOSP ~Binder 通信原理 (一) - 概要
猜你喜欢
阿里云的神龙架构是怎么工作的 | 科普图解
Use Zhiyun reader to translate statistical genetics books
漏电继电器JD1-100
全链路压测:影子库与影子表之争
Complete code of C language neural network and its meaning
ThinkPHP关联预载入with
LabVIEW is opening a new reference, indicating that the memory is full
No experts! Growth secrets for junior and intermediate programmers and "quasi programmers" who are still practicing in Universities
qt 简单布局 盒子模型 加弹簧
最长回文子串(动态规划)
随机推荐
Auto. JS get all app names of mobile phones
《2》 Label
How can project managers counter attack with NPDP certificates? Look here
Is the human body sensor easy to use? How to use it? Which do you buy between aqara green rice and Xiaomi
[Oracle] simple date and time formatting and sorting problem
漏电继电器JD1-100
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
删除文件时提示‘源文件名长度大于系统支持的长度’无法删除解决办法
数字化创新驱动指南
Longest common subsequence (LCS) (dynamic programming, recursive)
U++4 interface learning notes
【QT】自定义控件-Loading
ThinkPHP Association preload with
ScheduledExecutorService定时器
【js组件】自定义select
The sooner you understand the four rules of life, the more blessed you will be
Mysql database learning (7) -- a brief introduction to pymysql
Annotation初体验
QSlider of QT control style series (I)
项目经理如何凭借NPDP证书逆袭?看这里