不能使用与父子孙子相媲美的继承
2022-09-04 01:11:45
						给定以下代码:
public abstract class Participant {
    private String fullName;
    public Participant(String newFullName) {
        this.fullName = new String(newFullName);
    }
    // some more code 
}
public class Player extends Participant implements Comparable <Player> {    
    private int scoredGoals;
    public Player(String newFullName, int scored) {
        super(newFullName);
        this.scoredGoals = scored;
    }
    public int compareTo (Player otherPlayer) {
        Integer _scoredGoals = new Integer(this.scoredGoals);
        return _scoredGoals.compareTo(otherPlayer.getPlayerGoals());
    }
    // more irrelevant code 
}
public class Goalkeeper extends Player implements Comparable <Goalkeeper> { 
    private int missedGoals;        
    public Goalkeeper(String newFullName) {
        super(newFullName,0);
        missedGoals = 0;
    }
    public int compareTo (Goalkeeper otherGoalkeeper) {
        Integer _missedGoals = new Integer(this.missedGoals);
        return _missedGoals.compareTo(otherGoalkeeper.getMissedGoals());
    }
    // more code 
}
问题是这不会遵守。Goalkeeper
当我尝试编译该代码时,Eclipse 会抛出:
The interface Comparable cannot be implemented more than once with 
different arguments: Comparable<Player> and Comparable<Goalkeeper>
我不是想与 进行比较,而是与 ,并且只与他进行比较。PlayerGoalkeeper
我做错了什么?
 
					 
				 
				    		 
				    		 
				    		 
				    		