In Java generics, what does List<? super String> mean?

generics, java

Solution

No (i.e. yes, you have missed something :-) . `<? super String>` is any class which is a superclass of `String` (including `String` itself). (In this case, the only other suitable class is `Object`.)

What you described would be `<? extends String>` (which in this specific case wouldn't be very useful as `String` is `final`, so it can have no subclasses).

Problem

Can anyone explain how this both can compile and how it works? ``` List<? super String> list = new ArrayList<Object>(); ``` As I understood it, the implementation of this needs to be either a String list or a list of objects that have String as super class? Have I missed something?

Original source