I am having an error while compiling the following code involving a few generics:
public abstract class State<T extends HasAState<? extends State<T>>>{
protected T parent;
public void setParent(){ // It's been simplified for the sake of the question!
parent.removeState(this); // Error here!
this.parent = parent;
parent.addState(this); // Error here!
}
}
public interface HasAState<T extends State<? extends HasAState<T>>> {
public void addState(T state);
public void removeState(T state);
}
The errors are: The method removeState(capture#1-of ? extends State<T>) in the type HasAState<capture#1-of ? extends State<T>> is not applicable for the arguments (State<T>)
Actually what I would like to have is something like: class A implements HasAState
and class B extends State<A>
where B
has a reference to A
and can call A.addState(B)
(only because B
extends State<A>
) and where A
can call B.setParent(this)
.
How should I declare my classes so that what I intend to do work?
Thanks
is not applicable for the arguments (State
)`
– Jean Logeart Aug 25 '11 at 08:05