cannot cast and object from a lst which contains a base class
<p>I have an empty abstract base class</p>

<pre><code>abstract class Base{
    Base(){}
}
</code></pre>

<p>Then I have several classes that extend this base class</p>

<pre><code>class A extends Base{

}
</code></pre>

<p>Then I intantiate these classes and put into list.</p>

<pre><code> A it = new A();
 ArrayList&lt;Base&gt; list = new ArrayList&lt;Base&gt;();
 list.add(it);  // add A object
</code></pre>

<p>then I want to do something like</p>

<pre><code>   for(Base msg : List){
       if( msg instanceof A){
             A obj = (A)msg; 
        }

    }
But I'm getting errors.
</code></pre>

<p>What am I doing wrong</p>
