I have two classes, Player and Team. A player has a team field, and a team has a playerList field, containing the players on that team. When a player joins a team, the player's team field should be set to that team, and the team's playerList should add the player object joining. This is what I have so far, but is this not very recursive? How can I solve this problem? Example code is provided below.
public class Team {
private ArrayList<Player> playerList;
public void addPlayer(Player player){
playerList.add(player);
player.joinTeam(this);
}
}
public class Player {
private Team team;
public void joinTeam(Team team) {
this.team = team;
team.addPlayer(this)
}
}