java注解@Interface与Annotation 财富值96

2016-11-02 12:01发布

@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()==Configu‌​ration.class 结果是false, obj.getClass().getAnnotation(Configuration.class) instanceof Configuration为true, obj.getClass().getAnnotation(Configuration.class) instanceof Component为false

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
7条回答

obj.getClass().getAnnotation(Configuration.class).getClass() == Configu‌​ration.class 引用不同结果为false是正常情况。可以使用这种判断obj.getClass().getAnnotation(Configuration.class).getClass().getName().equals(Configu‌​ration.class.getName())

一周热门 更多>