Java包装集合
我需要包装五个类:linkedlist
,treeset
,hashset
,以及我自己创建的两个类
包装器和我的两个类都实现了同一个接口。 这是包装构造函数:
private Collection <String> collection;
public CollectionFacadeSet(java.util.Collection<java.lang.String> collection){
this.collection = collection;
}
现在,在另一个类中,我想创建一个5单元数组,每个单元包含一个不同的集合
这句话没问题:
static CollectionFacadeSet[] setArray = new CollectionFacadeSet[5];
但是,当我创建一个填充单元格的方法时:
private static void initializieArray(){
setArray[0] = CollectionFacadeSet(HashSet<String>);
}
这让我犯了一个错误:
Syntax error on token ">", Expression expected after this token
如何使用不同的集合类型启动每个单元
# 1 楼答案
数组将存储CollectionFacadeSet的对象,所以使用
new