我使用(键:字符串,值:ArrayList)将数据存储在HashMap中。我遇到问题的部分声明了一个新的 ArrayList“current”,在 HashMap 中搜索字符串“dictCode”,如果找到,则将 current 设置为返回值 ArrayList。
ArrayList current = new ArrayList();
if(dictMap.containsKey(dictCode)) {
current = dictMap.get(dictCode);
}
“current =...”行返回以下编译器错误:
Error: incompatible types
found : java.lang.Object
required: java.util.ArrayList
我不明白这一点...... HashMap 是否返回一个 Object 而不是我存储在其中的 ArrayList 作为值?如何将此对象转换为 ArrayList?
谢谢你。