Search code examples
aopaspectj

Pointcut that will capture constructor calls


I am trying to define a pointcut which will capture all the constructor calls, regardless of the modifier, return type, or class. I have used the following code

after():execution(* * * .new(..))

I am having an error :

Syntax error on token "*", "(" expected.

Can anybody suggest what may be the right approach?


Solution

  • Just remove the middle star "*". It does not make sense to specify a return type for a constructor call because it is clear that the constructor will always return an instance of the class it is defined for.

    after() : execution(* *.new(..))
    

    BTW, you should also remove the whitespace before ".new".