我添加到哈希表方法失敗,我做了什麼錯了?或者我錯過了什麼?哈希表接口,用於設置對象的實例的鍵
測試:
@Test
public void testAddKeyValue() {
AdminController cont = new AdminController();
Apartment o1 = new Apartment(1, 4, "Maier B", true);
ArrayList<Expense> exp = new ArrayList<>();
cont.addKeyWithList(o1, exp);
assertTrue(cont.isEmpty()); // ISSUE > the test works if it is true, but it is supposed be False.
}
回購類:
public class Repository extends HashMap<Apartment, ArrayList<Expense>>{
private Map<Apartment,ArrayList<Expense>> dic; // last expense object refers to curret month
Iterator<Map.Entry<Apartment, ArrayList<Expense>>> it;
public void addKeyWithList(Apartment apt, ArrayList<Expense> exp){
dic.put(apt, exp);
}
}
爲什麼不工作我的測試?或者在代碼中我做錯了什麼?
是你的代碼拋出異常?或者它只是沒有將元素添加到散列表? – PermGenError
您是否爲要放入Hashtable的類實現了equals()和hashcode()? – ntalbs
我也不明白爲什麼你的類'擴展了HashMap>'並且有一個相同類型的成員變量。 –
jlordo