我添加到哈希表方法失败,我做了什么错了?或者我错过了什么?哈希表接口,用于设置对象的实例的键
测试:
@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