我必須維護HashMap中每個鍵值的索引列表。 所以我宣佈HashMap爲我怎樣才能使HashSet作爲HashMap的參數?
HashMap<Integer,HashSet<Integer> hset = new HashSet<Integer>()> hm = new HashMap<Integer,HashSet<Integer> hset = new HashSet<Integer>()>();
但上述聲明似乎是不正確的。 所以我宣佈它作爲
HashSet<Integer> hset = new HashSet<Integer>();
但這裏的問題是,我怎麼能聲明存儲在HashSet的I,E Integer對象的類型,bacause在上述聲明中的HashSet的是rawtype。
也許你正在試圖做的'的HashMap <整數,HashSet的>置角=新的HashMap <整數,HashSet的>();'所以以後你可以做'hset.put(1,新HashSet ());'。我希望,這是你想要實現的。 –
這是簡單的通用類型。我不明白你在這裏感到困惑。嘗試給一些仿製藥。然後添加不同類型的對象到聲明的變量 – SacJn