【发布时间】:2018-04-20 01:54:26
【问题描述】:
考虑以下示例:
public static void main(String... args) {
List<? super IOException> exceptions = new ArrayList<Exception>();
exceptions.add(new Exception()); // Compile Error
exceptions.add(new IOException());
exceptions.add(new FileNotFoundException());
}
我知道下界通配符接受通配符中给定类的超类的所有类(此处为 IOException)。
为什么在上述情况下编译器会显示编译错误?
【问题讨论】:
-
如果是
ArrayList<IOException>会怎样?