【发布时间】:2019-11-28 10:09:40
【问题描述】:
HashMap<String, List<Person.Personal>> hashMap = new HashMap();
var attachment = new Person.Personal(name, surname, birthDate);
我需要使用来自另一个地图的键添加项目。
然后我需要如下代码;
if(hashMap.containsKey(courseGroup.getKey().get(0)))
{
hashMap.put(courseGroup.getKey().get(0), attachment);
}
else
{
hashMap.put(courseGroup.getKey().get(0), new Arraylist<Person.Personal> (attachment));
}
此代码显示错误: 无法解析构造函数 'Arraylist(Person.Personal)'
如果hashmap有key则添加它的value列表“attachment”,如果没有,创建一个list然后添加“attachment”,我需要。
【问题讨论】:
-
这里到底有什么问题?
-
查看
Map的方法getOrDefault -
是
attachmentPOJO还是ArrayList? -
问题已编辑:此代码显示错误:无法解析构造函数 'Arraylist(Person.Personal)'