use*_*468 6 java collections list
假设我有FooClass类.
public class FooClass {
}
Run Code Online (Sandbox Code Playgroud)
以下行给出了以下编译错误:
// Note I want to create an array of length 4 of Lists of FooClass
List<FooClass> runs[]=new List<FooClass>[4];
Run Code Online (Sandbox Code Playgroud)
Cannot create a generic array of List<FooClass> ...
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助.
// if you want create a List of FooClass (you can use any List implementation)
List<FooClass> runs = new ArrayList<FooClass>();
// if you want create array of FooClass
FooClass[] runs = new FooClass[4];
Run Code Online (Sandbox Code Playgroud)
UPD:
如果要创建列表数组,则应该:
例:
List<FooClass>[] runs = new List[4];
for (int i = 0; i < runs.length; i++) {
runs[i] = new ArrayList<>();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5431 次 |
| 最近记录: |