From the Coders at Work book discussing why generics were added in Java with Joshua Bloch:
My mental model was "Hey, collections are almost all homogenous - a list of strings, a map from String to Integer, or whatever. Yet by default they are heterogenous: they're all collections of objects and you have to cast on the way out and that's nonsense." Wouldn't it be much better if I could tell the system that this is a map from string to intergers and it would do the casting for me and it would catch it at compile time when I tried to do something wrong!Bloch notes that many of the additions to Java 5 were just automating in the compiler what was being done manually before by coders in the source files. The addition of generics drastically changed Java code. Before there were casts all over the place in for loops. Now type safety is taken for granted. To be truthful, it was rarely that a ClassCastException got past development or QA and became a runtime production issue. The casting was not really a quality issue. It did make programs look messy and generics have improved there in my opinion. Visually, the use of generics has changed Java code drastically. You never see a loop, collection or map happen without them now. Personally I think they were a positive addition.








