List<? extends Exception>
means you have a List
of some kind of exceptions but you don't know what kind of exceptions.
Because you don't know what kind of exceptions you need to insert, you cannot pass some special kind of exception to the list.
A List<? extends Exception>
could be a List<IllegalArgumentException>
and you cannot add a NullPointerException
to such a list.
However, you can retrieve Exception
s from such a list.
As the compiler knows that your List
contains some kind of Exception
, elements, you can call .get()
and assign the returned value to a variable of type Exception
but you cannot assign it to a subtype because the compiler doesn't know the actual subtype.
If you want to create a list of subtypes of exceptions, you might want to use a List<Exception>
as it also allows subtypes.