Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] implement an interface by subclassing

Hi all

I recently bumped into a problem using aspectJ that I can't seem to
explain. If I implement an interface by subclassing from a class that
happens to have the correct methods to implement the interface (but
doesn't implement the interface in intself), aspectJ advices are not
being executed with call or execution pointcuts for a method in the
implemented interface.

An example:

1) Interface to be implemented:

public interface SomeInterface {
	void someMethod();

2) Class with correct methods, without implementing the interface:

public class SomeClass {	
	public void someMethod() {
		System.out.println("some method in some class");

3) Subclass that implements the interface by extending from SomeClass:

public class SomeSubClass extends SomeClass implements SomeInterface {}

4) A simple aspect:

aspect SomeAspect {
    pointcut someCall(): call(void SomeInterface.someMethod());

    before(): someCall() {
        System.out.println("Entering: " + thisJoinPoint);

Now, when you call 'someMethod' on an instance of SomeSubClass, the
advice is not executed.

new SomeSubClass().someMethod();

When you let SomeClass implement the SomeInterface interface directly,
everything works as expected.

What am I missing here?

Thanx in advance

Back to the top