posted 7 years ago
Hi Samir. The wildcard ? is used to tell the compiler you really don't care what kind of list of numbers you get, as long as you can pull numbers out of it. The user is then free to input a List<Double> or a List<Integer> or whatever. When you use List<T extends Number>, you can also accept different kinds of lists of numbers, except you're telling the compiler that you actually care about the exact type, because you either want to use that type in your return value, or you want to make sure the list corresponds to the class' type argument.
An example:
With this class, if we have Cage<Feline> felineCage and List<Lion> lions, we can do felineCage.addAnimals(lions);
The T in the above code is used to express that we really care that our cage is filled with Felines. The ? is used to express that we really don't care what kind of collection of animals we add to the cage, as long as they're Feline.