public static <T> List<T> castList(Object obj, Class<T> clazz)
{
List<T> result = new ArrayList<T>();
if(obj instanceof List<?>)
{
for (Object o : (List<?>) obj)
{
result.add(clazz.cast(o));
}
return result;
}
return null;
}
public static void main(String[] args) {
Object obj = getObj();
List<User> list = castList(obj, User.class);
list.forEach(System.out::println);
}