Kotlin 编译错误:Unresolved reference: mutableListOf

发布时间: 2020-01-12 21:45:46 作者: 大象笔记

下面一段 Kotlin 代码在编译时报错:

class ResultListAdapter(val resultList: mutableListOf<PercentPrice>):
        RecyclerView.Adapter<ResultListAdapter.ResultViewHolder>() {

报错信息为:

Unresolved reference: mutableListOf

原来,mutableListOf 是一个函数方法,只能在类型 MutableList 初始化时使用。

所以,这里应该使用类 MutableList。

class ResultListAdapter(val resultList: MutableList<PercentPrice>):
        RecyclerView.Adapter<ResultListAdapter.ResultViewHolder>() {

mutableListOf 的使用范例

val prices = mutableListOf<PercentPrice>()
我是一名山东烟台的开发者,联系作者