Dieter Quickfend wrote:So if you assume that the Generic type of the ArrayList MUST be IOException or a supertype of IOException...
which types is this ArrayList guaranteed to be able to take as parameters?
Thanks for your reply. I would expect it to take an Exception or even an Object as its parameters but not somthing that's subtype of IOException. I thought the super wildcard is there to impose a restriction on the list to not allow any sub types of IOException. FileNotFoundException and EOFException are subtypes of IOException. Aren't they?
For example, the following code doesn't work and I cmpletely understand why it doesn't.
So, I still fail to understand why the code in my first post works.
Suman A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!
The super wildcard is there to guarantee that you do not pass a List with a Generic type that is a subtype of IOException.
Which means you could not do this:
List<? super IOException> arrayList = new ArrayList<FileNotFoundException>();
this will not work.
Now, this means the compiler just made sure that the generic type of the list you're passing is IOException or a superclass of IOException
And since we know that we can assign any object to a reference of its supertype in Java (for instance, a List<Exception> can take as a parameter in its add() method an Exception or any of its subclasses)...
What did the compiler just make sure?