1.
List<String>[] ls; Object[] objects = ls; objects[1] = new ArrayList<Integer>();
先把數組轉化為Object[] ,通過Object[]下標進行賦值.
2.
List<BerylliumSphere>[] spheres = (List<BerylliumSphere>[]) new List[10]; for(int i =0;i<spheres.length;i++) { spheres[i] = new ArrayList<BerylliumSphere>(); }
創建不帶具體類型的List比如new List[10],然后強行轉化為具體類型的List數組,編譯不會報錯,可以進行賦值.