Dongqing
Dongqing

Reputation: 686

Difference between @target and @annotation

In spring aop doc, it says:

@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

I think @target will match if the object has the given annotation like

@MyAnnotation
public class Foo {}

while @annotation will match the annotation on method, like :

public class Foo {

    @MyAnnotation
    public void doSomething() {}
}

Is my understanding correct?

Upvotes: 2

Views: 1148

Answers (1)

Dongqing
Dongqing

Reputation: 686

I opened this question based on this issue, wilkinsona gave the answer:

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

Upvotes: 1

Related Questions