Wilcards
Lets have a look at the below method definition
<T extends Human> int totalHumans(List<T> list) { }
<T extends Human> int totalHumans(List<T> list) { }
Here parameter T is only once in the method prototype, in an argument only.
You can assume that if the method body does not use the type T either.
In suca case you can use alternate syntax, called wildcards, It is denoted with ? symbol
int totalHumans(List<? extends Human> list) { }The two method definitions for totalHumans are similar.
The meaning of <? extends Human> is: It allows any type parameter as long as it is a
subclass of Human. Also when you use extends in any collection type parameter argument then you cannot manipulate that collection. You can only get elements from that collection.
Because it can lead to inappropriate data into collection if it allow to add data in that collection. Assume that collection is List<? extends Number> list, and assume you have pass the Integer list and inside method body you trying to add float data in that list. That is totally wrong. I hope you might have got some idea.