Generics allow you to write code that works with ANY type, but in a type-safe way.
In short:
Listlist=newArrayList();
list.add("Java");
list.add(10);// allowed 😱
Strings= (String) list.get(1);// Runtime error
Problems:
❌ No type safety
❌ Manual casting
❌ Runtime ClassCastException
List<String> list =newArrayList<>();
list.add("Java");
// list.add(10); ❌ compile-time error
Strings= list.get(0);// safe
💡 Errors caught early → safer code.