title: how to initialize List in java of an abstract type so I can add sub types to the list later
body: <p>tldr: how to create List of abstract type BankAccount and add concrete sub types to the list</p>
  
  <p>In java I have a class called BankAccount.  Its an abstract class because I don't want anyone to use a regular BankAccount ever, they should be using the sub types SavingsAccount, CheckingAccount, VacationAccount.</p>
  
  <p>I want to have a property in a customer class that is List called accounts.  In the class definition i added a property just like that and didnt initialize it to anything. In the constructor I want to add an account based on what the user specified in the constructor, however when i do this i get an error on the call to add().</p>
  
  <p>It looks something like this</p>
  
  <pre><code>List&lt;BankAccount&gt; accounts;
  
  accounts.add(new CheckingAccount() );
  </code></pre>
  
  <p>Should this work?  What am I doing wrong. I tried doing </p>
  
  <pre><code>List&lt;BankAccount&gt; accounts = new List&lt;BankAccount&gt;(); 
  </code></pre>
  
  <p>but that doesnt work. </p>