In book Spring in Action, I found following AspectJ point cut expression:
@Pointcut("execution(** concert.Performance.perform(..))")
void performance();
This will designate point cut performance to include methods whose name is "perform" and whose return type can be any. But notice it uses two stars (**) to match the return type, as I've experimented, one star (*) can perfectly do the job, this means the following line can do the same thing:
@Pointcut("execution(* concert.Performance.perform(..))")
void performance();
And I noticed that many AspectJ demos use two stars (**) to match "any return type", so is there some reason to do so? What is the problem of using one star to match "any return type"?
Spring documentation helps understand this better. It says
Spring AOP users are likely to use the execution pointcut designator the most often. The format of an execution expression is:
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern) throws-pattern?)
The first part modifiers-pattern
is optional as you can see it has suffixed with ?
. This is to designate method's access type.
So in your case, pointcut expression execution(** concert.Performance.perform(..))
advises execution of methods with any access modifier and any return type on the type concert.Performance
with method name perform
that has any argument type.
execution(* concert.Performance.perform(..))
means the same where the first *
is optional that denotes perform
method on the type concert.Performance
that accepts any type of arguments and method may have any return type(with optional access modifier meaning that access modifier can be anything).