比方说,我有一个通用类,如下所示:通配符相当于在C#泛型
public class GeneralPropertyMap<T>
{
}
在一些其他类我有需要在GeneralPropertyMap<T>
阵列的方法。在Java中,以便采取在包含任何类型的GeneralPropertyMap
的方法是这样的一个数组:
private void TakeGeneralPropertyMap(GeneralPropertyMap<?>[] maps)
{
}
我们使用通配符,这样以后我们可以称之为TakeGeneralPropertyMap
路过一堆GeneralPropertyMap
与任何类型T
每个,像这样:
GeneralPropertyMap<?>[] maps = new GeneralPropertyMap<?>[3];
maps[0] = new GeneralPropertyMap<String>();
maps[1] = new GeneralPropertyMap<Integer>();
maps[2] = new GeneralPropertyMap<Double>();
//And finally pass the array in.
TakeGeneralPropertyMap(maps);
我试图找出在C#中的等价物,但没有成功。有任何想法吗?
您是否尝试过制作功能拍摄'GeneralPropertyMap