Java - Object reference or identifier?
<p>I am currently creating a big project, and as such I would like to have everything worked out very well and as efficient as possible.</p>

<p>In my project, I have a class called Teams, which contains a HashMap(Integer, Team) of Team objects. Each instance of Team has a unique ID (integer).</p>

<p>There is also an object called Player. Each instance of Player can be assigned to a Team (but not always). </p>

<p>Now, I wonder what the best approach would be to know what Team a Player is assigned to:</p>

<p>-> Store the ID of the team in Player (private int team), this ID is then used to get the Team from the HashMap in Teams.</p>

<p>-> Store a reference to the Team in Player (private Team team)</p>

<p>Does anyone know which is better, and what the most important pro's, con's and dangers are of each?</p>

<p>Thanks!</p>
