Skip to main content

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

Hello Jan,
As per your design specification, the class "SomeSubClass" can be
manipulated either by type
"SomeClass" or by type "SomeInterface". In the other word you can write code
like :-

1.SomeInterface someSubClass = new SomeSubClass ();
or
2. SomeClass someSubClass = new SomeSubClass ();

The before advice defined by you, on call to void SomeInterface.someMethod()
will be initiated only when
you make instance of  "SomeInterface" to manupulate "SomeSubClass" object as
it has been shown in
point no. 1.

 I hope I have clarifiled your doubt.
with regards,
Ajay Kumar,
ST Microlelectronics Ltd.


Jan Van Besien-2 wrote:
> 
> 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
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> 

-- 
View this message in context: http://www.nabble.com/implement-an-interface-by-subclassing-tp16976310p16977479.html
Sent from the AspectJ - users mailing list archive at Nabble.com.



Back to the top