Fundamentals · Medium · Free
What are generics? Why List<String> is safer than raw List?
FresherFundamentalsOOP & Language Fundamentals
Generics
Generics add compile-time type parameters so collections are type-safe without casting. Raw types erase to Object and cause ClassCastException at runtime.
java
List<String> names = new ArrayList<>();
names.add("Ada");
// names.add(42); // compile errorMention type erasure lightly—you can't do
new T() without tricks.