Multiple classes in an (undefined) ArrayList?

This is the same as
ArrayList<Object> sampleList = new ArrayList<Object>();

Now an array list can hold objects of the <class> or any class that inherits from it. Since Object is the base class for all Java classes, including user defined classes your array list can hold objects of any type. The problem with this is that many poorly written programs crashed at runtime due to class casting exceptions.

This was the case before the Java developers introduced generics, now we type all our collections
ArrayList<MyUserClass> sampleList = new ArrayList<MyUserClass>();
The poorly written code is now detected at compile time so the running program is much more stable.

2 Likes