当前位置:网站首页>Annotation初体验
Annotation初体验
2022-07-06 23:23:00 【菜鸟xiaowang】
1.定义注解
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Person {
String name() default "abc";
int age() default 20;
}
2.使用注解
public class Student {
@Person(name = "王xx",age = 30)
public Object person;
}
3.处理注解
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.测试
PersonUtils.getPersonInfo(Student.class);
5.结果
边栏推荐
- U++ metadata specifier learning notes
- Using thread class and runnable interface to realize the difference between multithreading
- Why is the salary of test and development so high?
- Leetcode(46)——全排列
- 【QT】自定义控件-Loading
- How can professional people find background music materials when doing we media video clips?
- QT控件样式系列(一)之QSlider
- Leetcode (46) - Full Permutation
- 10 distributed databases that take you to the galaxy
- Test interview | how much can you answer the real test interview question of an Internet company?
猜你喜欢
Y58. Chapter III kubernetes from entry to proficiency - continuous integration and deployment (Sany)
Salesforce 容器化 ISV 场景下的软件供应链安全落地实践
Complete code of C language neural network and its meaning
Window scheduled tasks
【二叉树】二叉树寻路
EGR-20USCM接地故障继电器
If you‘re running pod install manually, make sure flutter pub get is executed first.
sublime使用技巧
Pytest testing framework -- data driven
高压漏电继电器BLD-20
随机推荐
U++ metadata specifier learning notes
sublime使用技巧
漏电继电器JOLX-GS62零序孔径Φ100
The founder has a debt of 1billion. Let's start the class. Is it about to "end the class"?
[opencv] image morphological operation opencv marks the positions of different connected domains
PMP证书有没有必要续期?
pytest测试框架——数据驱动
sublime使用技巧
全链路压测:影子库与影子表之争
做自媒体,有哪些免费下载视频剪辑素材的网站?
精彩速递|腾讯云数据库6月刊
设f(x)=∑x^n/n^2,证明f(x)+f(1-x)+lnxln(1-x)=∑1/n^2
Knapsack problem (01 knapsack, complete knapsack, dynamic programming)
How can professional people find background music materials when doing we media video clips?
Window scheduled tasks
[PHP SPL notes]
背包问题(01背包,完全背包,动态规划)
Techniques d'utilisation de sublime
线程同步的两个方法
NPDP产品经理认证,到底是何方神圣?