Given the following code :
public abstract class Participant {
private String fullName;
public Participant(String newFullName) {
this.fullName
As far as the logic of your design goes, you are not doing anything wrong. However, Java has a limitation that prevents you from implementing the same generic interface with different type parameters, which is due to the way it implements generics (through type erasure).
In your code, Goalkeeper
inherits from Player
its implementation of Comparable
, and tries to add a Comparable
of its own; this is not allowed.
The simplest way to address this limitation is to override Comparable
in the Goalkeeper
, cast the player passed in to Goalkeeper
, and compare it to this
goalkeeper.
Edit
public int compareTo (Player otherPlayer) {
Goalkeeper otherGoalkeeper = (Goalkeeper)otherPlayer;
Integer _missedGoals = new Integer(this.missedGoals);
return _missedGoals.compareTo(otherGoalkeeper.getMissedGoals());
}