Check if an object is instance of List of given class name
I think you can do it in two steps: First, you check it's a List.
if (o instanceof List)
Then, you check that one (each?) member of the list has the given type.
for (Object obj : (List) o) {
if (obj instanceof cls) {
doSomething();
}
}
It's because of Type Erasure. The statement
if (o instanceof List<cls>) {
doSomething();
}
will be executed at runtime, when the generic type of the list will be erased. Therefore, there's no point of checking for instanceof
generic-type.