[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] execution(method) and execution(constructor)


> I understand that when "super.bar();" is not present, the pointcut
> matches because SubFoo is also a Foo, so the execution of the
> method SubFoo.bar() should be also considered the execution of
> Foo.bar().

This is correct.
> But why after adding a super call, the pointcut matches twice?
Well, because you enter the execution of a method "bar" of a type Foo
twice: Once after the outermost call and once when calling the
super-implementation. In fact, the code in the advice body is inserted
into both methods, the one in Foo and the one in SubFoo.

> And why this is different for constructors?
Because of their inlining semantics. A constructor is not invoked via
invokevirtual but via invokespecial (such as private methods). This
means, that it is only looked up in the class you specify. When you call
super(), this causes the body of the super constructor to be copied into
the call site, this and nothing else.


Eric Bodden
Sable Research Group, McGill University
Montreal, Canada