当前位置:网站首页>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
边栏推荐
- DFS, BFS and traversal search of Graphs
- 《4》 Form
- Phenomenon analysis when Autowired annotation is used for list
- SQL injection HTTP header injection
- Simulate thread communication
- Leetcode(417)——太平洋大西洋水流问题
- Complete code of C language neural network and its meaning
- Error: No named parameter with the name ‘foregroundColor‘
- [PHP SPL notes]
- 照片选择器CollectionView
猜你喜欢
Pytest testing framework -- data driven
10 distributed databases that take you to the galaxy
张平安:加快云上数字创新,共建产业智慧生态
Mysql database learning (8) -- MySQL content supplement
在米家、欧瑞博、苹果HomeKit趋势下,智汀如何从中脱颖而出?
漏电继电器JELR-250FG
No experts! Growth secrets for junior and intermediate programmers and "quasi programmers" who are still practicing in Universities
Record a pressure measurement experience summary
Is it necessary to renew the PMP certificate?
Leetcode (417) -- Pacific Atlantic current problem
随机推荐
LinkedBlockingQueue源码分析-初始化
Mysql database learning (8) -- MySQL content supplement
QSlider of QT control style series (I)
《4》 Form
精彩速递|腾讯云数据库6月刊
Dbsync adds support for mongodb and ES
[PHP SPL notes]
DOM-节点对象+时间节点 综合案例
数字化创新驱动指南
Torch optimizer small parsing
删除文件时提示‘源文件名长度大于系统支持的长度’无法删除解决办法
背包问题(01背包,完全背包,动态规划)
全链路压测:影子库与影子表之争
CentOS 7.9 installing Oracle 21C Adventures
局部变量的数组初始化问题
AIDL 与Service
Two person game based on bevy game engine and FPGA
The sooner you understand the four rules of life, the more blessed you will be
Writing process of the first paper
【PHP SPL笔记】