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