Junior — Middle
In which version of Java were generics introduced?
sobes.tech AI
Answer from AI
Generics were introduced in Java starting from version Java 5 (J2SE 5.0). This allowed the creation of classes, interfaces, and methods with type parameters, which increased type safety and reduced the need for type casting.
Example of using generics:
List<String> list = new ArrayList<>();
list.add("Example");
String s = list.get(0); // Safe, without explicit casting