具有列表作爲值的散列映射定義:具有一個函數返回一個HashMap但MutableList在科特林,如何傳遞迴一個MutableList其中目標期望列表
fun getDataStatus(response: JSONObject?): HashMap<String, MutableList<DataStatus>> {
return HashMap<String, MutableList<AccountStatusAlert>>()
}
的值
private var mMap: HashMap<String, List<DataStatus>>? = null
結果時,傳遞給它遇到錯誤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 <字符串,列表>' –