Community
Participate
Working Groups
(From aspectj-users) The program below produces the erroneous message: [iajc] D:\workdir\DPsample\main\src\com\designpattern\observer\ObserverProt ocol.aj:39 [error] Type mismatch: cannot convert from Collection to Collection [iajc] return observers; [iajc] ^^^^^ //Subject.java interface Subject { public void addObserver(Observer observer); public void removeObserver(Observer observer); public Collection getObservers(); } //Observer.java interface Observer { public void update(); } //ObserverProtocol public abstract aspect ObserverProtocol{ abstract pointcut stateChange(Subject subject); after(Subject subject):stateChange(subject){ Iterator it=subject.getObservers().iterator(); while(it.hasNext()){ Observer observer=(Observer)it.next(); observer.update(); } } private Collection Subject.observers=new ArrayList(); public void Subject.addObserver(Observer observer){ observers.add(observer); } public void Subject.removeObserver(Observer observer){ observers.remove(observer); } public Collection Subject.getObservers() { return observers; } }
I'm out of the office most of today, will take another look at this tonight... Regards, Adrian.
ok, I made some progress on this on the train. The first piece of good news is that I can reliably reproduce it, and have a failing test case in the suite. I also know what the cause of the bug is :- the inter-type field has been given the (correct) type of Collection#RAW, but the return type of the inter-type method has the type Collection (the generic base type). The compiler compares the two types by identity and says that they are not the same, resulting in the confusing error message. Now all I need to do is find out why the itd method does not also present its return type as raw....
fix now committed in tree.