Problem with generic overriding...
I am trying to make a generic version of the Java Observer/Observable definitions, but have a problem getting it to compile.
The idea is to just provide a type-checked wrapper to the actual Java library.
The problem is on NotifyObservers, which gets the error:
Name clash: The method notifyObservers(A) of type ObservableD<S,O,A> has the same erasure as notifyObservers(Object) of type Observable but does not override it.
If I try to specify that it should override it (@Override), then it also complains:
The method NotifyObservers(A) of type Observable<S,O,A> must override a superclass method.
So, seems like it complains that it does match, and also doesn't.
?
* Generic version of Observer/Observable
*-- Derived
*
* The idea is thatthis version is usedfor type-checking by compiler,
* and then the library version actually gets loaded...
*
* From Wadler; ...
*/
//
interface ObserverD<Sextends ObservableD><S,O,A>,
Oextends ObserverD <S,O,A>,
A >{
publicvoid update ( S subject, A arg);
}
//
abstractclass ObservableD<Sextends ObservableD><S,O,A>,
Oextends ObserverD <S,O,A>,
A >extends java.util.Observable{
publicvoidaddObserver(O o){super.addObserver((java.util.Observer)o);};
protectedvoidclearChanged(){super.clearChanged();};
publicintcountObservers(){return super.countObservers();};
publicvoiddeleteObserver(O o){super.deleteObserver((java.util.Observer)o);};
publicbooleanhasChanged(){return super.hasChanged();};
publicvoidnotifyObservers(){super.notifyObservers();};
// @Override
publicvoidnotifyObservers(A a){super.notifyObservers((Object)a);};
protectedvoidsetChanged(){super.setChanged();};
}

