@Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Component { String value() default ""; } @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Component public @interface Configuration { String value() default ""; } 我有一个对象被@Configuration注解,那我怎么知道它还是被Component注解的?@Interface 和接口Annotation是什么关系?
有一个注解了@Configuration的对象, obj.getClass().getAnnotation(Configuration.class).getClass()==Configuration.class 结果是false, obj.getClass().getAnnotation(Configuration.class) instanceof Configuration为true, obj.getClass().getAnnotation(Configuration.class) instanceof Component为false
付费偷看金额在0.1-10元之间
注:
Meta-Annotations并不是Annotation的原生功能,只是在spring中实现了这种机制。如果单纯的使用原生的Annotation则需要自己解析Meta-Annotations实现相应的功能才行。@Component只是@Configuration的注解声明,并不表示@Configuration就是@Component类型没听懂
obj.getClass().getAnnotation(Configuration.class).getClass() == Configuration.class引用不同结果为false是正常情况。可以使用这种判断obj.getClass().getAnnotation(Configuration.class).getClass().getName().equals(Configuration.class.getName())我有一个对象被@Configuration注解,那我怎么知道它还是被Component注解的?
@interface是声明注解的关键字(与class/interface一样)Annotation也可以获取自身的注解。一周热门 更多>