List<Object> obj = new ArrayList<Object>();
obj.add(new A());
It is not the right way to write code. Basically you are creating a generic List and adding Object to it and it type unsafe and keep any Object type.
List<Object> obj = new ArrayList<Object>();
obj.add(new A());
obj.add(new String("str"));
obj.add(1);
It is recommended to create type-safe List
like List<A> obj = new ArrayList<A>();
you can do this in such a way -
public <T>List<T> castCollection(List srcList, Class<T> clas){
List<T> list =new ArrayList<T>();
for (Object obj : srcList) {
if(obj!=null && clas.isAssignableFrom(obj.getClass()))
list.add(clas.cast(obj));
}
return list;
}