title: How to check if a subclass is an instance of a class at runtime?
body: <p>In an android app test suite I have a class like this where <code>B</code> is a view:</p>
  
  <pre><code>public class A extends B {
  ... etc...
  }
  </code></pre>
  
  <p>now I have a list of view objects which may contain <code>A</code> objects but in this case I only care if they're subclasses or "instances of" <code>B</code>. I'd like to do something like:</p>
  
  <pre><code>ArrayList&lt;View&gt; viewList = getViews();
  Iterator&lt;View&gt; iterator = viewList.iterator();
  while (iterator.hasNext() &amp;&amp; viewList != null) {
      View view = iterator.next();
      if (view.getClass().isInstance(B.class)) {
          // this is an instance of B
      }
  }
  </code></pre>
  
  <p>The problem is that when the <code>if</code> encounters an <code>A</code> object it doesn't evaluate to an "instance of <code>B</code>". Is there a way to do <code>isSubclassOf</code> or something?</p>