I have;
List stringList = new ArrayList();
List integerList = new ArrayList();
Is
Had the same problem, but I used instanceof instead. Did it this way:
List<Object> listCheck = (List<Object>)(Object) stringList;
if (!listCheck.isEmpty()) {
if (listCheck.get(0) instanceof String) {
System.out.println("List type is String");
}
if (listCheck.get(0) instanceof Integer) {
System.out.println("List type is Integer");
}
}
}
This involves using unchecked casts so only do this when you know it is a list, and what type it can be.
The type is erased so you will not be able to. See http://en.wikipedia.org/wiki/Type_erasure and http://en.wikipedia.org/wiki/Generics_in_Java#Type_erasure