title: Correct way to cast a list of objects from a parent class to various child classes
body: <p>I have a base class called <code>Game</code> and multiple child classes such as <code>NFLGame</code>, <code>NBAGame</code>, <code>NHLGame</code>, and so on, and in my code, I'm putting a bunch of these child objects into an array defined as: </p>
  
  <p><code>ArrayList&lt;Game&gt; games = new ArrayList&lt;&gt;();</code></p>
  
  <p>And then to read each game in the array I can think of two options of how to access them.</p>
  
  <ol>
  <li><p>Make a long <code>if/else if</code> chain or a <code>switch</code> to check which child class the game belongs to using <code>instanceof()</code> and then cast it to the correct child class.</p></li>
  <li><p>Use a hash table technique that uses a key id that is assigned to every child class and have the value be a call to an interface method that casts to the correct child class. I should add that this is the method I am currently using because eventually I want to add a lot more leagues which would make this a more cleaner and efficient approach.</p></li>
  </ol>
  
  <p>But my question is: are these the only two options available when reading objects of multiple child classes from a list/array or is there a better way to go about this?</p>
  
  <p>EDIT:</p>
  
  <p>As requested here is my Game class:</p>
  
  <pre><code>public abstract class Game
  {
      private String mHomeTeamName, mAwayTeamName, mGameStartTimeLocal, mHomeTeamLogoSrc, mAwayTeamLogoSrc;
      private String mHomeTeamFullName, mAwayTeamFullName;
      private String mHomeTeamRecord, mAwayTeamRecord, mHomeTeamScore, mAwayTeamScore;
      private boolean mGameEnded, mIsGamePostponed, mIsChecked;
      private boolean mWasAddedToCheckedGamesMap;
      private int mLeagueID;
      private String mLeagueName, mGameDateTimeUTC, mGameDateUTC, mGameID;
      private Date mGameDate;
  
      public Game(int leagueID, String leagueName)
      {
          mLeagueID = leagueID;
          mLeagueName = leagueName;
      }
  
      public Game(String homeTeam, String homeTeamFullName, String awayTeam, String awayTeamFullName,
                  String gameStartTimeLocal, String homeTeamRecord, String awayTeamRecord, String homeTeamLogoSrc,
                  String awayTeamLogoSrc, String homeTeamScore, String awayTeamScore, boolean gameEnded,
                  boolean isGamePostponed, String leagueName, int leagueID, Date gameDate,
                  String gameDateTimeUTC, String gameDateUTC)
      {
          mHomeTeamName = homeTeam;
          mAwayTeamName = awayTeam;
          mHomeTeamFullName = homeTeamFullName;
          mAwayTeamFullName = awayTeamFullName;
          mGameStartTimeLocal = gameStartTimeLocal;
          mHomeTeamRecord = homeTeamRecord;
          mAwayTeamRecord = awayTeamRecord;
          mHomeTeamLogoSrc = homeTeamLogoSrc;
          mAwayTeamLogoSrc = awayTeamLogoSrc;
          mHomeTeamScore = homeTeamScore;
          mAwayTeamScore = awayTeamScore;
          mGameEnded = gameEnded;
          mIsGamePostponed = isGamePostponed;
          mLeagueName = leagueName;
          mLeagueID = leagueID;
          mGameDate = gameDate;
          mGameDateUTC = gameDateUTC;
          mGameDateTimeUTC = gameDateTimeUTC;
          mIsChecked = false;
      }
  }
  </code></pre>