java 注解详解

注解与反射:


//获取当前对象上所有的注解
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()
==========================================================================================================================

posted @ 2019-12-31 11:23  骑驴晒太阳  阅读(267)  评论(0)    收藏  举报