Is it really necessary to use the ‘extends BoardGame’?
If I remove it my code still works, but I’m not sure if I should.
I’m doing that because of the copy() method.
Any suggestions.
Thanks
public interface BoardGame<GAME extends BoardGame>
{
GAME getGame();
BoardGame<GAME> copy();
int currentPlayer();
boolean isGameOver();
int getTotalMoves();
BoardResult getOutcome(int playerIndex);
void makeMove(int moveIndex);
void addMoveObserver(BoardGameMoveObserver observer);
}
Both are ok in a sense that they compile ok.
If you use
<GAME extends BoardGame>than all implementations will need to use type parameter that extends BoardGame. This makes sense if any of the methods takes parameter or returns value that is GAME.In your case that is
getGame(). So in case of<GAME extends BoardGame>all users of ofgetGame()can count that return value is (at least) BoardGame. But in the case of ,getGame()could return any type the implementing class defined..