Of course, calling the sum90 method on this List will result in a ClassCastException because it will try to cast a String to an Integer . Heterogeneous collections such as those found in Java are not type safe because you can put many different types of objects into the collection at the same time. A lack of type safety is not always a problem. However, in order to do anything beyond the methods defined on the Object base class, you will have to cast the object back to its actual type. As this example shows, such indiscriminate casts can be dangerous.
Extra casting is also a performance problem, and it clutters the readability of code.
All in all, a lack of generics results in extra headaches for the developer. The next example presents a new List that takes advantage of generics. For this reason, this way of implementing generics is sometimes referred to as parametric polymorphism. The Sum method will now accept only List s of Integers . However, when you use generics, the compiler will catch this error at compile time.