Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Execution pointcut semantics

Folks,

I wondered if somebody could explain the semantics of the execution pointcut
in the context of inheritance. Consider the following example.

public class Class0 { 
	public void m() {
		System.out.println("m");
	}
}

public class Class1 extends Class0 {
}

public class Class2 extends Class1 {
}

public class Client {
	public static void main(String[] args) {
		Class2 c = new Class2();
		c.m();
	}
}

public aspect A {
	pointcut p() : execution(public void Class1.m());
	before() : p() {
		System.out.println(thisJoinPoint);
	}
}

When running this example, p() does not match the execution of c.m(). Notice
that Class1 is the class specified in the pointcut, and that m() is not
declared in Class1. However, Class1 inherits m() from Class0, and so does
Class2. A call pointcut would match in this situation, so there is obviously
a difference in the semantics of the two.

What confuses me though, is that if we add m() to Class2:

public class Class2 extends Class1 {
	public void m() {
		System.out.println("m");
	}
}

The pointcut p() matches. But this happens only if both Class0 and Class2
declares m(), not just one of them. Why is this, and what is the matching
rule coming into play here? Is it overriding that somehow is the key?

Jon

http://www.eecs.wsu.edu/~jbaekken/




Back to the top