你这话有问题吧,如果你定义的泛型限定是<? super SonOne>
那么只有SonOne 和Father 类的参数时可以编译通过
如果你定义的泛型限定是<? super SonTwo>
那么只有SonTwo和Father类的参数时可以编译通过
如果你定义的泛型限定是<? super Father>
那么只有Father类的参数时可以编译通过
当你用了不匹配的类型的时候就会报错,如图
/**
javaSE day15-12泛型限定
*/
import java.util.*;
class GenericDemo7
{
public static void main(String[] args)
{
ArrayList<Person> al = new ArrayList<Person>();
al.add(new Person("abc1"));
al.add(new Person("abc2"));
al.add(new Person("abc3"));
printColl(al);
ArrayList<Student> all = new ArrayList<Student>();
all.add(new Student("abc---1"));
all.add(new Student("abc--2"));
all.add(new Student("abc--3"));
printColl(all);//ArrayList<Person> al = ArrayList<Student>();error
} //指向和接收左右两边要一致
public static void printColl(ArrayList<? super Person> al)