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?
No (i.e. yes, you have missed something 🙂 .
<? super String>is any class which is a superclass ofString(includingStringitself). (In this case, the only other suitable class isObject.)What you described would be
<? extends String>(which in this specific case wouldn’t be very useful asStringisfinal, so it can have no subclasses).