简体   繁体   中英

Generics wildcard parameter lower bound to Object

It is possible to specify a wildcard type that has a lower bound to Object :

public void method(Collection<? super Object> c) {
    // compiles, but ? can only be Object
}

Logically the unknown type can only be Object (no type is above Object in the class hierarchy).

Is there ever a requirement or good reason to use a type of <? super Object> <? super Object> ?

yes, there is a use case for "? super XXXXXX", as outlines here . the gist is the using user/extends will make your collection either read only or write only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM