title: Java: cast collection type to subtype
body: <p>Suppose class <code>B</code> extends class <code>A</code>. I have a <code>List&lt;A&gt;</code> that I happen to know <em>only</em> contains instances of <code>B</code>. Is there a way I can cast the <code>List&lt;A&gt;</code> to a <code>List&lt;B&gt;</code>?</p>
  
  <p>It seems my only option is to iterate over the collection, casting one element at time, creating a new collection. This seems like an utter waste of resources given type erasure makes this completely unnecessary at run-time.</p>