比方說,我有一個通用類,如下所示:通配符相當於在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