通常数组不能够很好的和泛型结合。你不能实例化具有参数类型的数组。
List<String> [] ss = new ArrayList<String>[10];
报错:Cannot create a generic array of ArrayList<String>
通俗点讲就是
List<String> [] ss是带参数的数组,这种数组不能够实例化,也就是创建数据对象。
为什么会这样?因为数组必须知道它的确切类型,以强制保障类型安全。
曙光:你可以参数化方法,编译器的确不允许你创建参数话数组,允许你创建对这种数组的引用。
List<String> [] ss;
List<BerylliumSphere>[] spheres = (List<BerylliumSphere>[]) new List[10];
for (int i = 0; i < spheres.length; i++)
spheres[i] = new ArrayList<BerylliumSphere>();
这是合法的。