Sorry I had the wrong code before…
So I have an interface that looks like:
public interface Player {
void setPartner(Player partner);
}
And I have an implementation of that interface that looks something like this:
public class Human implements Player
{
private Human partner;
public void setPartner(Human partner)
{
this.partner = partner;
}
}
So the compiler says that I am not implementing every method from Player which indicates to me that I have to match the parameter type of the setPartner method exactly, even though the a Human, is a Player. Is there any good way of getting around this or implementing this differently?
You cannot have covariant parameters (what happens if you manipulate your Human instance through the Player interface?), however you can use generics.
However, you can’t force the implementing class to actually use its own type as the type parameter of Player.