当前位置:网站首页>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.结果
边栏推荐
- ClickHouse(03)ClickHouse怎么安装和部署
- 带你遨游银河系的 10 种分布式数据库
- Full link voltage test: the dispute between shadow database and shadow table
- 10 distributed databases that take you to the galaxy
- 背包问题(01背包,完全背包,动态规划)
- Inventory host list in ansible (I wish you countless flowers and romance)
- 【PHP SPL笔记】
- [question] Compilation Principle
- Leetcode(417)——太平洋大西洋水流问题
- If you‘re running pod install manually, make sure flutter pub get is executed first.
猜你喜欢
JHOK-ZBL1漏电继电器
一个酷酷的“幽灵”控制台工具
DJ-ZBS2漏电继电器
Batch normalization (Standardization) processing
If you‘re running pod install manually, make sure flutter pub get is executed first.
Is it necessary to renew the PMP certificate?
IMS data channel concept of 5g vonr+
高压漏电继电器BLD-20
AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘
Window scheduled tasks
随机推荐
Redis如何实现多可用区?
If you‘re running pod install manually, make sure flutter pub get is executed first.
JS 的 try catch finally 中 return 的执行顺序
Window scheduled tasks
c语言神经网络基本代码大全及其含义
torch optimizer小解析
U++4 interface learning notes
数字化创新驱动指南
app内嵌h5---iphone软键盘遮挡输入文字
What changes will PMP certification bring?
LabVIEW在打开一个新的引用,提示内存已满
Harmonyos fourth training
Two methods of thread synchronization
Techniques d'utilisation de sublime
Using thread class and runnable interface to realize the difference between multithreading
创始人负债10亿,开课吧即将“下课”?
数字化如何影响工作流程自动化
U++ game learning notes
腾讯云数据库公有云市场稳居TOP 2!
CentOS 7.9安装Oracle 21c历险记