Now you'll get an exception. As you know generics is all about compile time type safety. So you won't get any exception when you add a
String to an <Integer> List. Because a typed collection can have any type of elements added to it if you can fool the compiler, as for the JVM a typed collection is not different from raw collection. When you get an element out of a typed collection, the compiler inserts a type caste at that statement. So in the above case the compiler inserts a cast which results in an exception. The actual code which the JVM sees looks something like this
When you used a println statement, you didn't get any exception because the println method takes Object as a parameter, so the compiler doesn't inserts any cast...