title: How can check if we can cast an object to another?
body: <p>How can check if we can cast an object to another?</p>
  <p>I have an object that it is an Arraylist of instances of an class that can be dynamically in 2 other class. How can I check that I can cast my object to each of them Arraylist class?</p>
  <p>For example:</p>
  <ul>
  <li>My classes are class1, class2 and class3.</li>
  <li>My object is obj.</li>
  </ul>
  <p>I want check it:</p>
  <pre><code>ArrayList&lt;class1&gt; ar1=new Arraylist&lt;class1&gt;();
  ar1=(ArrayList&lt;class1&gt;)obj;
  </code></pre>
  <p>How can I check if it can be true or false?</p>