title: Unchecked cast in Java when casting to list of superclasses
body: <p>In my Java program, I need to cast an object of type <code>List&lt;? extends SomeBaseClass&gt;</code> to <code>List&lt;SomeBaseClass&gt;</code>. If I cast it directly the compiler complains (shows a warning) that there is an unchecked cast. Even though I can be sure that all the objects can be converted to their superclass, the compiler does not notice it and reports an unchecked cast. How can I get rid of the warning? Is there any other way than @SupressWarnings("unchecked")?</p>
  
  <p>P.S.: The code works fine, I am just curious whether there is a better way of doing things.</p>
  
  <p>Edit:</p>
  
  <p>Solution: One should only do this type of cast if he is sure the he will not change the list in the future. But it is better to cast individual objects when we take them out of the list.</p>