Get instanceof type out of an array without if statements
<p>Note: This is an abstracted version of my problem as a lot of actual code would probably be confusing and irrelevant to the problem.</p>

<p>I have an array/ArrayList of objects that all inherit their information from another class.</p>

<p>For example</p>

<pre><code>class A

class B extends A

class C extends A

class D extends A
</code></pre>

<p>Objects of class B, C, and D all go into an array of type A.</p>

<p>Now when they come out I want to cast them back to the original type to use a specific method / variable etc. <strong>How can I do this without having to go through a set of <em>if</em> statements to try and find out what sort of sub class it is?</strong> It makes my code very inflexible as I have to write a new set of <em>if</em> statements every time I add a new class that extends class A. Is there a way to simply return to the exact name of the class that an object is?</p>
