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

边栏推荐
- Two methods of thread synchronization
- Full link voltage test: the dispute between shadow database and shadow table
- Under the trend of Micah, orebo and apple homekit, how does zhiting stand out?
- Array initialization of local variables
- DJ-ZBS2漏电继电器
- Complete code of C language neural network and its meaning
- 磁盘监控相关命令
- Leetcode (46) - Full Permutation
- SQL injection cookie injection
- Dynamically generate tables
猜你喜欢

Intelligent annotation scheme of entity recognition based on hugging Face Pre training model: generate doccano request JSON format

JHOK-ZBG2漏电继电器

Harmonyos fourth training

U++ game learning notes

y58.第三章 Kubernetes从入门到精通 -- 持续集成与部署(三一)

Auto. JS get all app names of mobile phones

照片选择器CollectionView

全链路压测:影子库与影子表之争

Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem

10 distributed databases that take you to the galaxy
随机推荐
Is it necessary to renew the PMP certificate?
Tencent cloud database public cloud market ranks top 2!
【QT】自定义控件-Loading
Longest common subsequence (LCS) (dynamic programming, recursive)
How does redis implement multiple zones?
Life experience of an update statement
pytest测试框架——数据驱动
Longest non descent subsequence (LIS) (dynamic programming)
利用OPNET进行网络指定源组播(SSM)仿真的设计、配置及注意点
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
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
Mysql database learning (7) -- a brief introduction to pymysql
U++ metadata specifier learning notes
Addressable 预下载
QSlider of QT control style series (I)
Pytest testing framework -- data driven
DFS, BFS and traversal search of Graphs
Most commonly used high number formula
Auto.js 获取手机所有app名字
As we media, what websites are there to download video clips for free?