Class<List<Integer>> tListInt3 = (Class<List<Integer>>) ((Class<Integer>)List.class);
那行不通。你可能是说
Class<List<Integer>> tListInt3 = (Class<List<Integer>>) ((Class)List.class);
我们总是可以通过上下转换从一种类型转换为另一种类型
Integer x = (Integer)(Object)"string";
的类型
List.class是
Class<List>;它不是子类型/超类型,
Class<List<Whatever>>因此在两种类型之间直接转换是非法的。
可以争论的是
Class<List<Integer>>不存在-只有一个类
List;
没有此类
List<Integer>(实际上只是
List在运行时)
但是,这是Java类型系统的缺陷。在实践中,我们确实需要这样的东西
Class<List<Integer>>。我们的解决方案-
铸造和假装
Class<List<Int>>出口-同样存在缺陷-但这不是我们的错。



