简体   繁体   English

泛型通配符参数下限为Object

[英]Generics wildcard parameter lower bound to Object

It is possible to specify a wildcard type that has a lower bound to Object : 可以指定具有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). 逻辑上,未知类型只能是Object (类层次结构中没有类型高于 Object )。

Is there ever a requirement or good reason to use a type of <? super Object> 有没有要求或有充分理由使用<? super Object> <? super Object> ? <? super Object>

yes, there is a use case for "? super XXXXXX", as outlines here . 是的,有一个用例“?超级XXXXXX”,如概述这里 the gist is the using user/extends will make your collection either read only or write only. 要点是使用user / extends会使您的集合只读或只写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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