D. Ogranos wrote:
They enable the compiler to spot obvious mistakes like inserting integers into string lists. But on the byte code level there isn't a difference between a generic and non-generic list.
In the second case the compiler creates code that just takes Object elements from the list, and passes them to the PrintStream.println(Object) method
I assume that in the second case, the compiler ("knowing" that he has a list of Integers) just creates code that uses the "toString()" method of the objects in the list. So the code will run without problems.
For the first case? Again assuming, the compiler expects String objects, so he doesn't use the toString() method. Then the virtual machine finds that the object type is in fact not String. Integer is not convertible to String so you get the exception.