Given the following code :
public abstract class Participant {
private String fullName;
public Participant(String newFullName) {
this.fullName
The problem is described in Angelika Langer's Generics FAQ #401:
Can a class implement different instantiations of the same generic interface?
No, a type must not directly or indirectly derive from two different instantiations of the same generic interface.
The reason for this restriction is the translation by type erasure. After type erasure the different instantiations of the same generic interface collapse to the same raw type. At runtime there is no distinction between the different instantiations any longer.
(I highly recommend checking out the whole description of the problem: it's more interesting than what I've quoted.)
In order to work around this restriction, you can try the following:
public class Player extends Participant implements Comparable {
// ...
public int compareTo(E otherPlayer) {
Integer _scoredGoals = this.scoredGoals;
return _scoredGoals.compareTo(otherPlayer.getPlayerGoals());
}
// ...
}
public class Goalkeeper extends Player {
// ...
@Override
public int compareTo(Goalkeeper otherGoalkeeper) {
Integer _missedGoals = this.missedGoals;
return _missedGoals.compareTo(otherGoalkeeper.getMissedGoals());
}
// ...
}