title: How to handle a collection of a base class if subtype references are required, without saving things twice?
body: <p>I have some base Class A and some (B, C, D, E) different subclasses. All instances of A come from an external data source (database) and I have to infer the actual type at runtime (with marker atttributes stored in the database) and I have no option to change this behaviour.</p>
  
  <p>I end up with a List allAs. At runtime several algorithms have to be executed, that perform on subclasses of A, i.e. I have some algo(List bs), algo(List cs), ... functions and to call them I need to extract all B's, C's or whatever I need from the List. 
  On the other hand there are algorithms performing on collections of A's.</p>
  
  <p>The following follows:</p>
  
  <ul>
  <li>At some point I need to save references to instances of A's</li>
  <li>At some point I need to save references to instances of subclasses</li>
  <li>All this data has to be synchronized</li>
  </ul>
  
  <p>The question is, what are best / bad practices to achieve this?
  Following solutions come to my mind:</p>
  
  <ul>
  <li>Stick to the List allAs and call as.stream().filter() to extract sublists of given subclasses
  each time I have to call a subclass-algorithm</li>
  <li>Create a seperate list for each subclass, and combine them all if I need to call an algorithm<br>
  that acts on instances of the base class</li>
  <li>Do both, but then on update / add / delete actions I need to perform them on each of the lists<br>
  (which I need anyways for the second solution)</li>
  </ul>
  
  <p>My intuition tells me that the cleanest way would be to stick to the first principle, but this gets performance critical since I have to handle much data such that filtering the whole collection each time is not viable.</p>