码迷,mamicode.com
首页 > 编程语言 > 详细

java 注解详解

时间:2019-12-31 12:53:36      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:function   ace   stc   present   集合   inter   获取   generics   name   

注解与反射:


//获取当前对象上所有的注解
Annotation[] annotations = obj.getClass().getAnnotations();
//获取当前对象上指定注解
RestController speciAnno = obj.getClass().getAnnotation(RestController.class);
//获取class对象的直接超类的
Type genericSuperclass = class1.getGenericSuperclass();
//获取class对象的所有接口的type集合
Type Type[] interfaceTypes = class1.getGenericInterfaces();
//判断是否被某个注解类修饰 
boolean isAnnotationPresent = class1.isAnnotationPresent(Deprecated.class);
==========================================================================================================================
//获取字段上某指定注解
field.getAnnotation(FruitName.class);
//获取字段上所有注解
field.getAnnotations()

//判断当前字段上是否有注解
field.isAnnotationPresent()
 
==========================================================================================================================
//获取当前方法的所有注解
method.getAnnotations()

//获取方法的指定注解
Autowired uc = method.getAnnotation(Autowired.class);

//判断当前方法上是否有注解
method.isAnnotationPresent()
==========================================================================================================================

java 注解详解

标签:function   ace   stc   present   集合   inter   获取   generics   name   

原文地址:https://www.cnblogs.com/qlsty/p/12121094.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!