How has bounded wildcards (? extends / ? super) changed in recent Java versions?

In recent Java versions, the use of bounded wildcards has remained a powerful feature allowing developers to define generic classes and methods with better type flexibility. Wildcards such as ? extends and ? super have not changed in functionality, but understanding how they work with generics has become increasingly important with the growing use of Java in large-scale applications.

Bounded wildcards help in controlling the type of objects a method can accept and return, thus increasing the reusability and safety of code. The major difference in recent Java updates lies in enhancing the context in which these wildcards are typically used, especially with collections and inheritance.

Example of Bounded Wildcards

List<? extends Number> numbers = new ArrayList<Integer>(); // Can read from 'numbers', but cannot add to it, except for null. Number num = numbers.get(0); List<? super Integer> list = new ArrayList<Number>(); // Can add Integer to 'list' list.add(10);

bounded wildcards ? extends ? super Java generics type flexibility generics in Java