【发布时间】:2018-03-20 21:03:31
【问题描述】:
拥有一个以 List 作为值定义的 hashMap:
private var mMap: HashMap<String, List<DataStatus>>? = null
有一个函数返回一个 hashMap 但具有 MutableList 的值
fun getDataStatus(response: JSONObject?): HashMap<String, MutableList<DataStatus>> {
return HashMap<String, MutableList<AccountStatusAlert>>()
}
将结果传递给期望 List 的 hashMap 时出现错误:
mMap = getDataStatus(resp) //<== got error
出现错误:
Error:(81, 35) Type mismatch: inferred type is HashMap<String,
MutableList<DataStatus>> but HashMap<String, List<DataStatus>>? was expected
【问题讨论】:
-
据我所知,您必须将表达式转换为
HashMap<String, List<DataStatus>>
标签: android list inheritance kotlin