As for the logic of your design, you are not doing anything wrong. However, Java has a limitation that prevents you from implementing the same general interface with different type parameters, which is related to how it implements generics (via type erasure).
In your code, Goalkeeper
inherits from its Player
implementation of Comparable <Player>
and tries to add its own Comparable <Goalkeeper>
; it is not allowed.
The easiest way to eliminate this restriction is to override Comparable <Player>
in Goalkeeper
, transfer the player transferred to Goalkeeper
, and compare it with this
goalkeeper.
Edit
public int compareTo (Player otherPlayer) { Goalkeeper otherGoalkeeper = (Goalkeeper)otherPlayer; Integer _missedGoals = new Integer(this.missedGoals); return _missedGoals.compareTo(otherGoalkeeper.getMissedGoals()); }
dasblinkenlight
source share