Project: AspectJ
Bug 108902 Type mismatch: cannot convert from Collection to Collection
Reported: 2005-09-07 02:53:36 | Status: resolved fixed

(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; } }

Files changed in fix:
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java tests/bugs150/pr108902/Observer.java tests/bugs150/pr108902/Subject.java tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java