I agree with Alexander, and indeed when I compiled your code I saw the error I expected (AspectJ 1.8.5):
ajc -1.5 *.java *.aj /Users/aclement/provaBug/ClassImplementingInterf.java:3 [error] The type ClassImplementingInterf must implement the inherited abstract method MyInterface.myMethod() public class ClassImplementingInterf {
AspectJ wants to ensure the type system is consistent when you are applying ITDs. Here you have said a class implements an interface but you haven’t provided an implementation for the method, it is an error. In your more recent reply you said " If i had to implement directly the interface by hard coding it in the classes i can also specify an implements clause in the class declaration, isn't it?” - yes, you could, but you don’t have to directly implement the interface by hard coding it in the class. You can use an ITD for it:
public aspect ConcreteAspect extends MyAspect { declare parents: ClassImplementingInterf implements MyInterface;
// implementors of this interface not providing an implementation of this method will get this one public void MyInterface.myMethod(){ System.out.println("myMethod"); }
pointcut mypointcut(): call(public void OtherClass.method(int)); pointcut interfacemethod(): call(void *.*.myMethod()); } So no changes required in ClassImplementingInterf. This pattern above is very common.
I’m surprised you aren’t seeing errors like the one above, I wonder what compilation sequence you are using to build the pieces. Why haven’t I gotten around to implementing traits :)
cheers, Andy
Hi and thanks for the reply,
Well I think that adding an interface with declare parents and not specifying an implementation is not a problem in AspectJ, if it were not so, what should serve declare parents? If i had to implement directly the interface by hard coding it in the classes i can also specify an implements clause in the class declaration, isn't it?
I know it's a strange behaviour to add an interface with aspectj and pretend that classes works as the interface was present, but i'm trying to create an aspect that implements the GoF command pattern (like in the work of Jan Hannemann and Gregor Kiczales https://www.cs.ubc.ca/labs/spl/projects/aodps.html )
And I want to underline that everything work fine except the implicit cast when extracting the ClassImplementingInferf instance from the collection.
I've made some other tests and i found out that MyInterface var2 = (MyInterface)(ClassImplementingInterf)x.get(0);
Works fine, but
MyInterface fromLst = x.get(0);
throw ClassCastException
I think it's a strange behaviour!
I hope i was clearer. Regards, Luca
_______________________________________________ aspectj-users mailing list aspectj-users@xxxxxxxxxxxTo change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/aspectj-users
|