@target 和@annotation 的区别

Difference between @target and @annotation

在 spring aop 文档中,它说:

@target - limits matching to join points (the execution of methods when using Spring AOP) where the class of the executing object has an annotation of the given type

@annotation - limits matching to join points where the subject of the join point (method being executed in Spring AOP) has the given annotation

我认为如果对象具有像

这样的给定注释,@target 将匹配
@MyAnnotation
public class Foo {}

而@annotation 将匹配方法上的注释,例如:

public class Foo {

    @MyAnnotation
    public void doSomething() {}
}

我的理解对吗?

我根据这个打开了这个问题issue, wilkinsona给出了答案:

The key difference is that @target matches the runtime type whereas @annotation matches the statically declared type.