Java泛型超级关键字
super
List<? super Number> list = null;list.add(new Integer(0)); //this compileslist.add(new Object());//this doesn't compile
NumberObjectNumberInteger
static void test(List<? super Number> param) {
param.add(new Integer(2));}public static void main(String[] args) {
ArrayList<String> sList = new ArrayList<String>();
test(sList); //will never compile, however...}String is Object, Object is superclass of Number. So String should work.
<S super T><? super T>
相关分类