Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] 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: SomeInterface.java

public interface SomeInterface {
	void someMethod();
}

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

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

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

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
Jan


Back to the top