【发布时间】:2018-08-07 15:40:55
【问题描述】:
在简单的情况下,我可以轻松地从泛型类型降级为通配符类型:
List<Integer> intList = new ArrayList<>();
List<?> wildList = intList; // I can cast to a List<?>
但是,随着我的泛型变得越来越复杂:
List<List<Integer>> nestedIntList = new ArrayList<>();
List<List<?>> nestedWildList = nestIntList; // This does not compile
有没有办法可以编译?我是否遗漏了编译器保护我免受某些合乎逻辑的情况?为什么我不能转换内部类型?
【问题讨论】: