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

边栏推荐
- 【问道】编译原理
- DJ-ZBS2漏电继电器
- Timer create timer
- Longest common subsequence (LCS) (dynamic programming, recursive)
- 一文搞懂常见的网络I/O模型
- Wonderful express | Tencent cloud database June issue
- 2039: [蓝桥杯2022初赛] 李白打酒加强版 (动态规划)
- 使用知云阅读器翻译统计遗传学书籍
- SQL injection - secondary injection and multi statement injection
- 人体传感器好不好用?怎么用?Aqara绿米、小米之间到底买哪个
猜你喜欢

漏电继电器JELR-250FG

SQL injection - secondary injection and multi statement injection

AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘

ThinkPHP关联预载入with

No experts! Growth secrets for junior and intermediate programmers and "quasi programmers" who are still practicing in Universities

Leetcode(46)——全排列

动态生成表格

《四》表单

《二》标签

pmp真的有用吗?
随机推荐
Torch optimizer small parsing
Redis如何实现多可用区?
模拟线程通信
Basic knowledge of road loss of 3GPP channel model
Development thoughts of adding new requirements in secondary development
Test interview | how much can you answer the real test interview question of an Internet company?
【问道】编译原理
《四》表单
ThinkPHP关联预载入with
pmp真的有用吗?
做自媒体,有哪些免费下载视频剪辑素材的网站?
Auto.js 获取手机所有app名字
Harmonyos fourth training
Leetcode(417)——太平洋大西洋水流问题
The execution order of return in JS' try catch finally
SQL injection cookie injection
np.random.shuffle与np.swapaxis或transpose一起时要慎用
最长不下降子序列(LIS)(动态规划)
[opencv] image morphological operation opencv marks the positions of different connected domains
人体传感器好不好用?怎么用?Aqara绿米、小米之间到底买哪个